{"id":13638439,"url":"https://github.com/anki-code/xontrib-onepath","last_synced_at":"2025-03-21T08:31:21.678Z","repository":{"id":62590096,"uuid":"295527679","full_name":"anki-code/xontrib-onepath","owner":"anki-code","description":"Associate files and directories with app or alias and run it without preceding commands in xonsh shell.","archived":false,"fork":false,"pushed_at":"2023-04-07T15:18:48.000Z","size":76,"stargazers_count":18,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T16:44:08.544Z","etag":null,"topics":["shell","xonsh","xontrib"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anki-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"custom":["https://github.com/anki-code","https://www.buymeacoffee.com/xxh","https://github.com/xonsh/xonsh#the-xonsh-shell-community"]}},"created_at":"2020-09-14T20:12:11.000Z","updated_at":"2024-08-24T17:01:31.000Z","dependencies_parsed_at":"2024-01-29T10:09:28.253Z","dependency_job_id":"c49eba9f-5fd3-4549-8780-fcf4b45b4987","html_url":"https://github.com/anki-code/xontrib-onepath","commit_stats":{"total_commits":78,"total_committers":2,"mean_commits":39.0,"dds":"0.46153846153846156","last_synced_commit":"eae2648e3575f17e58b93fc0d88b99ea3cdfd76c"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-onepath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-onepath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-onepath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-onepath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anki-code","download_url":"https://codeload.github.com/anki-code/xontrib-onepath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244765018,"owners_count":20506747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["shell","xonsh","xontrib"],"created_at":"2024-08-02T01:00:45.849Z","updated_at":"2025-03-21T08:31:21.236Z","avatar_url":"https://github.com/anki-code.png","language":"Python","funding_links":["https://github.com/anki-code","https://www.buymeacoffee.com/xxh","https://github.com/xonsh/xonsh#the-xonsh-shell-community"],"categories":["Plugins"],"sub_categories":["Prompt tweaks"],"readme":"\u003cp align=\"center\"\u003e\nWhen you click to a file or folder in graphical OS they will be opened in associated app. The xontrib-onepath brings the same logic to the \u003ca href=\"https://github.com/xonsh/xonsh/\"\u003exonsh shell\u003c/a\u003e. Type the filename or path without preceding command and an associated action will be executed. The actions are customizable.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e  \nIf you like the idea click ⭐ on the repo and \u003ca href=\"https://twitter.com/intent/tweet?text=Nice%20xontrib%20for%20the%20xonsh%20shell!\u0026url=https://github.com/anki-code/xontrib-prompt-bar\" target=\"_blank\"\u003etweet\u003c/a\u003e.\n\u003c/p\u003e\n\n## Install\n```bash\nxpip install -U xontrib-onepath\necho 'xontrib load onepath' \u003e\u003e ~/.xonshrc\n# Reload xonsh\n```\n\n## Examples\n```bash\n# Run:                 # Action that will be executed:                       \n/                      # cd /\nexecutable_script      # ./executable_script\n.xonshrc               # vim ~/.xonshrc\n~/Downloads/logo.png   # xdg-open ~/Downloads/logo.png\ngit                    # git\n./git                  # cd ./git\n```\n\n## Default actions\nIf typed command is a registered name (i.e. `git`) and `which` command returns the path (i.e. `/usr/bin/git`) it will be executed. \nIn other case the typed path will be used to make action. Default actions: \n\n| Priority | Type  | Action  |\n|---|---|---|\n| 1 | `\u003cDIR\u003e`  | `cd`  | \n| 2 | `\u003cXFILE\u003e`  | `\u003cRUN\u003e`  | \n| 3 | `text/` | `vim`|\n| 4 | `image/` | `xdg-open` |\n\n#### Help to add more types and best default actions. PRs are welcome!\n\nYou can add platform and tool depend actions:\n\n```xsh\nimport shutil as _shutil\nfrom xonsh.platform import ON_LINUX #, ON_DARWIN, ON_WINDOWS, ON_WSL, IN_APPIMAGE, ON_CYGWIN, ON_MSYS, ON_POSIX, ON_FREEBSD, ON_DRAGONFLY, ON_NETBSD, ON_OPENBSD\n\nxontrib load onepath\n\nif ON_LINUX and _shutil.which('nvim'):\n    $XONTRIB_ONEPATH_ACTIONS['text/'] = 'nvim'\n```\n\n## File types\n\n| # | Type    | Example  |\n|---|---------|----------|\n| 1 | Full path to file.                | `~/.xonshrc`     |\n| 2 | File name.                        | `file.txt`        | \n| 3 | File extension.                   | `*.txt`           |\n| 4 | MIME type/subtype and extension.  | `text/plain.txt`  |\n| 5 | MIME type/subtype.                | `text/plain`      |\n| 6 | MIME type.                        | `text/`           |\n| 7 | Any file.                         | `\u003cFILE\u003e` (constant) |\n| 8 | Any executable file.              | `\u003cXFILE\u003e` (constant)|\n| 9 | Any directory.                    | `\u003cDIR\u003e` (constant)  |\n| 10| Any file or directory.            | `*` (constant)    |\n\nTo get MIME type for the file run `file --mime-type --brief \u003cfile\u003e`.\n\n## Examples of actions\n\nUse `XONTRIB_ONEPATH_ACTIONS` environment variable to add new actions.\nIf you need more complex actions use [callable xonsh aliases](https://xon.sh/tutorial.html#callable-aliases).\n\n### Simple actions\n```python\n$XONTRIB_ONEPATH_ACTIONS['text/'] = 'vim'            # Use vim to open any text file\n$XONTRIB_ONEPATH_ACTIONS['.xonshrc'] = 'vim'         # vim for `.xonshrc` file\n$XONTRIB_ONEPATH_ACTIONS['*.log'] = 'tail'           # tail for text type *.log files\n$XONTRIB_ONEPATH_ACTIONS['text/plain.txt'] = 'less'  # less for plain text *.txt files \n$XONTRIB_ONEPATH_ACTIONS['\u003cDIR\u003e'] = 'ls'             # list the files in the directory\n$XONTRIB_ONEPATH_ACTIONS['application/zip'] = 'als'  # list files in zip file using atool\n```\n\n#### Run xsh regardless the execution permissions\n\n```python\n$XONTRIB_ONEPATH_ACTIONS = {'*.xsh':'xonsh', **$XONTRIB_ONEPATH_ACTIONS}  # Insert on top\nxontrib load onepath\nscript.xsh                            # the same as:  chmod +x script.xsh \u0026\u0026 ./script.xsh\n```\n\n#### View CSV tables using pandas\n```python\nimport pandas as pd\ndef _view_csv_with_pandas(args):\n    print(pd.read_csv(args[0]))\n\naliases['view_csv_with_pandas'] = _view_csv_with_pandas\ndel _view_csv_with_pandas\n\n$XONTRIB_ONEPATH_ACTIONS['application/csv'] = 'view_csv_with_pandas'\n```\n\n#### cd \u0026 ls\n```python\ndef _cdls(args):\n     cd @(args[0])\n     if int($(ls | wc -l).strip()) \u003c 100:\n         ls --group-directories-first -a --color\naliases['cdls'] = _cdls\ndel _cdls\n\n$XONTRIB_ONEPATH_ACTIONS['\u003cDIR\u003e'] = 'cdls'\n```\n\n## Debug\n\nTo enable debug mode run `$XONTRIB_ONEPATH_DEBUG = True`.\n\n## Known issues\n\n### ImportError: failed to find libmagic\n\nInstall libmagic: `brew install libmagic`.\n\n### NTFS in Linux: all files have execute permission\nIf you mount NTFS partition with default permissions then all files will have execute permission \nand `onepath` will execute them instead of action. The right way \nis to [change default `/etc/fstab` settings](https://askubuntu.com/questions/113733/how-do-i-correctly-mount-a-ntfs-partition-in-etc-fstab).\nExample:\n```bash\nsudo umount /d\nsudo mount -o uid=1000,gid=1000,dmask=027,fmask=137 /d \nls -la /d\n```\n\n## Links \n* This package is the part of [ergopack](https://github.com/anki-code/xontrib-ergopack) - the pack of ergonomic xontribs.\n* This package was created with [xontrib template](https://github.com/xonsh/xontrib-template).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanki-code%2Fxontrib-onepath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanki-code%2Fxontrib-onepath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanki-code%2Fxontrib-onepath/lists"}