xontrib-skim


Namexontrib-skim JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/eugenesvk/xontrib-skim
Summaryskim (fuzzy finder) integration
upload_time2024-07-20 12:17:29
maintainerNone
docs_urlNone
authorEvgeny
requires_python<4.0,>=3.9
licenseMIT
keywords xontrib xonsh
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
<a href="https://github.com/lotabout/skim">skim</a> (fuzzy finder) integration into <a href="https://xon.sh/">xonsh</a> (shell)
<br>
Sets up keybinds to search various type of data: dirs/files, history of commands/CWDs/dirs, ssh hosts...
</p>


## Install

```xsh
xpip install -U xontrib-skim
# or: xpip install -U git+https://github.com/eugenesvk/xontrib-skim
```

## Use

Supported data sources:

  - xonsh history of commands (and their frequency)
  - xonsh history of commands' CWDs (and the frequency of commands started here)
  - zoxide's history of dirs
  <br/> CWDs/dirs support multi-selection (with proper escape-quoting) as well as `cd`-ing to the selected dir in-place
  - files in the current directory and its sub-directories
  - dirs in the current directory and its sub-directories
  - ssh hosts from `/etc/ssh/ssh_config`, `~/.ssh/config`, `~/.ssh/known_hosts`

This xontrib requires `sk` (or `sk-tmux`) to be in `PATH`. If it's added to `PATH` via another xontrib (e.g, you installed it via Homebrew and use `xontrib-homebrew`), then you should load this xontrib after the one setting `PATH`

1. Add the following to your `.py` xontrib loading config and `import` it in your xonsh run control file (`~/.xonshrc` or `~/.config/rc.xsh`):
```py
from xonsh.xontribs 	import xontribs_load
from xonsh.built_ins	import XSH
envx = XSH.env

xontribs = [ "skim", # Initializes skim (Fuzzy Finder)
 # your other xontribs
]
# ↓ optional configuration variables (use `False` to disable a keybind)
if 'skim' in xontribs: # Configure skim only if you're actually loading it
  #Config var                 	  Value	 	  	 ≝Default         ¦Alt_cmd	  Comment
  envx["X_SKIM_KEY_HIST"]     	= "⎈   	 	s"	#≝c-s              ¦False 	Search in xonsh 's history entries      and ⎀insert the chosen command
  envx["X_SKIM_KEY_HIST_CWD→"]	= "    	⎇	s"	#≝['escape','s']   ¦False 	Search in xonsh 's history entries' CWD and →CD to  the selected item (if exists, do nothing otherwise)
  envx["X_SKIM_KEY_HIST_CWD"] 	= "⎈   	⎇	s"	#≝['escape','c-s'] ¦False 	Search in xonsh 's history entries' CWD and ⎀insert the selected item(s)
  envx["X_SKIM_KEY_HIST_Z→"]  	= "    	⎇	z"	#≝['escape','z']   ¦False 	Search in zoxide's history entries      and →CD to  the selected item (if exists, do nothing otherwise)
  envx["X_SKIM_KEY_HIST_Z"]   	= "⎈   	⎇	z"	#≝['escape','c-z'] ¦False 	Search in zoxide's history entries      and ⎀insert the selected item(s)
  envx["X_SKIM_KEY_FILE"]     	= "⎈   	 	f"	#≝c-f              ¦False 	Find files in the current directory and its sub-directories
  envx["X_SKIM_KEY_DIR"]      	= "    	⎇	f"	#≝['escape','f']   ¦False 	Find dirs  in the current directory and its sub-directories
  envx["X_SKIM_KEY_SSH"]      	= "⎈   	 	b"	#≝c-b              ¦False 	Run 'ssh HOST' for hosts in /etc/ssh/ssh_config, ~/.ssh/config, ~/.ssh/known_hosts

  # run to see the allowed list for ↑: from prompt_toolkit.keys import ALL_KEYS; print(ALL_KEYS)
  # Alt is also supported as either of: a- ⎇ ⌥ (converted to a prefix 'escape')
  # Control symbols are also supported as either of: ⎈ ⌃
  # ↓ are key bindings for the skim binary itself, not this xontrib, so use skim rules https://github.com/lotabout/skim#keymap
  #Config var                   	  Value         	 ≝Default	¦Alt_cmd	Comment
  envx["X_SKIM_KEY_SORT_TOGGLE"]	= "ctrl-r"      	#≝ctrl-r 	¦False  	⎈R binding for 'toggle-sort'
  envx["X_SKIM_KEY_CUSTOM"]     	= None          	#≝None   	¦{'key':'action'}
  envx["X_SKIM_NO_HEIGHT"]      	= True          	#≝True   	¦False	disable `--height` to fix a skim bug
  envx["X_SKIM_NO_SORT"]        	= True          	#≝True   	¦False	disable history sorting
  envx["X_SKIM_CMD_FRQ"]        	= True          	#≝True   	¦False	add ∑command runs for a given command
  envx["X_SKIM_CMD_FRQ_MIN"]    	= 5             	#≝5      	¦     	hide frequency numbers below this
  envx["X_SKIM_CWD_FRQ"]        	= True          	#≝True   	¦False	add ∑command runs at a given CWD
  envx["X_SKIM_CWD_FRQ_MIN"]    	= 5             	#≝5      	¦     	hide frequency numbers below this
  envx["X_SKIM_CMD_FIND"]       	= "fd -t f -t l"	#≝None   	      	command used by skim to search for files
  envx["X_SKIM_CMD_FIND_DIR"]   	= "fd -t d     "	#≝None   	      	command used by skim to search for directories
  envx["X_SKIM_DIR_VIEW"]       	= "ls -F --color=always {2..}" #≝None   preview function for Dir lists
  envx["SKIM_DEFAULT_OPTIONS"]  	= "--ansi --preview-window=right:40%:wrap" #≝None   other options to pass to skim

xontribs_load(xontribs) # actually load all xontribs in the list
```

2. Or just add this to your xonsh run control file
```xsh
xontrib load skim # Initializes skim (fuzzy finder)
# configure like in the example above, but replace envx['VAR'] with $VAR
$X_SKIM_KEY_HISTORY	= "c-s" # ...
```

## Examples

- `cd` to a path in-place without losing the command you've already typed in the prompt!

    1. Press <kbd>⎇</kbd><kbd>s</kbd> (for command history CWD's) or <kbd>⎇</kbd><kbd>z</kbd> (for zoxide's history) to launch fuzzy finder of your favorite dirs<br/>
![cd inplace 1](<./doc/img/cd inplace 1.png>)

    2. Find the correct dir and insert it<br/>
![cd inplace 2](<./doc/img/cd inplace 2.png>)

    3. The prompt is updated in the background, reflecting the dir change and preserving the command<br/>
![cd inplace 3](<./doc/img/cd inplace 3.png>)

- Find fils/dirs in xonsh-completed paths: type `cd ~/Mus`; hit <kbd>⎈</kbd><kbd>F</kbd> to limit your file search to `~/Music`

- Find files with <kbd>⎈</kbd><kbd>F</kbd> and dirs with <kbd>⎇</kbd><kbd>F</kbd>
```py
envx["X_SKIM_KEY_FILE"]	= "⎇f"
envx["X_SKIM_KEY_DIR"] 	= "⎈f"
```

- Insert multiple paths with home row cursor keys
  <br/><kbd>⎇</kbd><kbd>J</kbd> to toggle and ▼
  <br/><kbd>⎇</kbd><kbd>K</kbd> to toggle and ▲
  ```py
  envx["X_SKIM_KEY_CUSTOM"]	= {
    'alt-j':'toggle+down'  	,
    'alt-k':'toggle+up'    	}
  ```

## Known issues

- skim doesn't clear the screen properly when `--height` is set due to a [bug](https://github.com/lotabout/skim/issues/494). At the moment this flag is disabled via `X_SKIM_NO_HEIGHT`
- skim sometimes prints extraneous text symbols, e.g., when searching history, maybe due to [this bug](https://github.com/lotabout/skim/issues/502) or something else
- skim might bug in tmux on some system/terminals [bug1](https://github.com/lotabout/skim/issues/482), [bug2](https://github.com/lotabout/skim/issues/412) 
- `toggle-sort` (and `X_SKIM_KEY_SORT_TOGGLE`) doesn't seem to be supported in skim, `ls | sk --bind=pgdn:toggle-sort` also fails
- to remove extra `?[38;5;26mFOLDER` from output, add `--ansi` to `$SKIM_DEFAULT_OPTIONS` or disable colors in your `$X_SKIM_CMD_FIND`/`DIR` filter (e.g., `fd -t d -c never`)
- <kbd>⎈</kbd>/<kbd>⎇</kbd><kbd>f</kbd> conflict with [xontrib-output-search](https://github.com/anki-code/xontrib-output-search)'s defaults

## Credits

This package was created with [xontrib template](https://github.com/xonsh/xontrib-template)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eugenesvk/xontrib-skim",
    "name": "xontrib-skim",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "xontrib, xonsh",
    "author": "Evgeny",
    "author_email": "es.bugzilla@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/99/b1/bede332d114828fbb99b57550ad1f9e4615ff7a3d3b4a55e98fba52ec596/xontrib_skim-0.0.6.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n<a href=\"https://github.com/lotabout/skim\">skim</a> (fuzzy finder) integration into <a href=\"https://xon.sh/\">xonsh</a> (shell)\n<br>\nSets up keybinds to search various type of data: dirs/files, history of commands/CWDs/dirs, ssh hosts...\n</p>\n\n\n## Install\n\n```xsh\nxpip install -U xontrib-skim\n# or: xpip install -U git+https://github.com/eugenesvk/xontrib-skim\n```\n\n## Use\n\nSupported data sources:\n\n  - xonsh history of commands (and their frequency)\n  - xonsh history of commands' CWDs (and the frequency of commands started here)\n  - zoxide's history of dirs\n  <br/> CWDs/dirs support multi-selection (with proper escape-quoting) as well as `cd`-ing to the selected dir in-place\n  - files in the current directory and its sub-directories\n  - dirs in the current directory and its sub-directories\n  - ssh hosts from `/etc/ssh/ssh_config`, `~/.ssh/config`, `~/.ssh/known_hosts`\n\nThis xontrib requires `sk` (or `sk-tmux`) to be in `PATH`. If it's added to `PATH` via another xontrib (e.g, you installed it via Homebrew and use `xontrib-homebrew`), then you should load this xontrib after the one setting `PATH`\n\n1. Add the following to your `.py` xontrib loading config and `import` it in your xonsh run control file (`~/.xonshrc` or `~/.config/rc.xsh`):\n```py\nfrom xonsh.xontribs \timport xontribs_load\nfrom xonsh.built_ins\timport XSH\nenvx = XSH.env\n\nxontribs = [ \"skim\", # Initializes skim (Fuzzy Finder)\n # your other xontribs\n]\n# \u2193 optional configuration variables (use `False` to disable a keybind)\nif 'skim' in xontribs: # Configure skim only if you're actually loading it\n  #Config var                 \t  Value\t \t  \t \u225dDefault         \u00a6Alt_cmd\t  Comment\n  envx[\"X_SKIM_KEY_HIST\"]     \t= \"\u2388   \t \ts\"\t#\u225dc-s              \u00a6False \tSearch in xonsh 's history entries      and \u2380insert the chosen command\n  envx[\"X_SKIM_KEY_HIST_CWD\u2192\"]\t= \"    \t\u2387\ts\"\t#\u225d['escape','s']   \u00a6False \tSearch in xonsh 's history entries' CWD and \u2192CD to  the selected item (if exists, do nothing otherwise)\n  envx[\"X_SKIM_KEY_HIST_CWD\"] \t= \"\u2388   \t\u2387\ts\"\t#\u225d['escape','c-s'] \u00a6False \tSearch in xonsh 's history entries' CWD and \u2380insert the selected item(s)\n  envx[\"X_SKIM_KEY_HIST_Z\u2192\"]  \t= \"    \t\u2387\tz\"\t#\u225d['escape','z']   \u00a6False \tSearch in zoxide's history entries      and \u2192CD to  the selected item (if exists, do nothing otherwise)\n  envx[\"X_SKIM_KEY_HIST_Z\"]   \t= \"\u2388   \t\u2387\tz\"\t#\u225d['escape','c-z'] \u00a6False \tSearch in zoxide's history entries      and \u2380insert the selected item(s)\n  envx[\"X_SKIM_KEY_FILE\"]     \t= \"\u2388   \t \tf\"\t#\u225dc-f              \u00a6False \tFind files in the current directory and its sub-directories\n  envx[\"X_SKIM_KEY_DIR\"]      \t= \"    \t\u2387\tf\"\t#\u225d['escape','f']   \u00a6False \tFind dirs  in the current directory and its sub-directories\n  envx[\"X_SKIM_KEY_SSH\"]      \t= \"\u2388   \t \tb\"\t#\u225dc-b              \u00a6False \tRun 'ssh HOST' for hosts in /etc/ssh/ssh_config, ~/.ssh/config, ~/.ssh/known_hosts\n\n  # run to see the allowed list for \u2191: from prompt_toolkit.keys import ALL_KEYS; print(ALL_KEYS)\n  # Alt is also supported as either of: a- \u2387 \u2325 (converted to a prefix 'escape')\n  # Control symbols are also supported as either of: \u2388 \u2303\n  # \u2193 are key bindings for the skim binary itself, not this xontrib, so use skim rules https://github.com/lotabout/skim#keymap\n  #Config var                   \t  Value         \t \u225dDefault\t\u00a6Alt_cmd\tComment\n  envx[\"X_SKIM_KEY_SORT_TOGGLE\"]\t= \"ctrl-r\"      \t#\u225dctrl-r \t\u00a6False  \t\u2388R binding for 'toggle-sort'\n  envx[\"X_SKIM_KEY_CUSTOM\"]     \t= None          \t#\u225dNone   \t\u00a6{'key':'action'}\n  envx[\"X_SKIM_NO_HEIGHT\"]      \t= True          \t#\u225dTrue   \t\u00a6False\tdisable `--height` to fix a skim bug\n  envx[\"X_SKIM_NO_SORT\"]        \t= True          \t#\u225dTrue   \t\u00a6False\tdisable history sorting\n  envx[\"X_SKIM_CMD_FRQ\"]        \t= True          \t#\u225dTrue   \t\u00a6False\tadd \u2211command runs for a given command\n  envx[\"X_SKIM_CMD_FRQ_MIN\"]    \t= 5             \t#\u225d5      \t\u00a6     \thide frequency numbers below this\n  envx[\"X_SKIM_CWD_FRQ\"]        \t= True          \t#\u225dTrue   \t\u00a6False\tadd \u2211command runs at a given CWD\n  envx[\"X_SKIM_CWD_FRQ_MIN\"]    \t= 5             \t#\u225d5      \t\u00a6     \thide frequency numbers below this\n  envx[\"X_SKIM_CMD_FIND\"]       \t= \"fd -t f -t l\"\t#\u225dNone   \t      \tcommand used by skim to search for files\n  envx[\"X_SKIM_CMD_FIND_DIR\"]   \t= \"fd -t d     \"\t#\u225dNone   \t      \tcommand used by skim to search for directories\n  envx[\"X_SKIM_DIR_VIEW\"]       \t= \"ls -F --color=always {2..}\" #\u225dNone   preview function for Dir lists\n  envx[\"SKIM_DEFAULT_OPTIONS\"]  \t= \"--ansi --preview-window=right:40%:wrap\" #\u225dNone   other options to pass to skim\n\nxontribs_load(xontribs) # actually load all xontribs in the list\n```\n\n2. Or just add this to your xonsh run control file\n```xsh\nxontrib load skim # Initializes skim (fuzzy finder)\n# configure like in the example above, but replace envx['VAR'] with $VAR\n$X_SKIM_KEY_HISTORY\t= \"c-s\" # ...\n```\n\n## Examples\n\n- `cd` to a path in-place without losing the command you've already typed in the prompt!\n\n    1. Press <kbd>\u2387</kbd><kbd>s</kbd> (for command history CWD's) or <kbd>\u2387</kbd><kbd>z</kbd> (for zoxide's history) to launch fuzzy finder of your favorite dirs<br/>\n![cd inplace 1](<./doc/img/cd inplace 1.png>)\n\n    2. Find the correct dir and insert it<br/>\n![cd inplace 2](<./doc/img/cd inplace 2.png>)\n\n    3. The prompt is updated in the background, reflecting the dir change and preserving the command<br/>\n![cd inplace 3](<./doc/img/cd inplace 3.png>)\n\n- Find fils/dirs in xonsh-completed paths: type `cd ~/Mus`; hit <kbd>\u2388</kbd><kbd>F</kbd> to limit your file search to `~/Music`\n\n- Find files with <kbd>\u2388</kbd><kbd>F</kbd> and dirs with <kbd>\u2387</kbd><kbd>F</kbd>\n```py\nenvx[\"X_SKIM_KEY_FILE\"]\t= \"\u2387f\"\nenvx[\"X_SKIM_KEY_DIR\"] \t= \"\u2388f\"\n```\n\n- Insert multiple paths with home row cursor keys\n  <br/><kbd>\u2387</kbd><kbd>J</kbd> to toggle and \u25bc\n  <br/><kbd>\u2387</kbd><kbd>K</kbd> to toggle and \u25b2\n  ```py\n  envx[\"X_SKIM_KEY_CUSTOM\"]\t= {\n    'alt-j':'toggle+down'  \t,\n    'alt-k':'toggle+up'    \t}\n  ```\n\n## Known issues\n\n- skim doesn't clear the screen properly when `--height` is set due to a [bug](https://github.com/lotabout/skim/issues/494). At the moment this flag is disabled via `X_SKIM_NO_HEIGHT`\n- skim sometimes prints extraneous text symbols, e.g., when searching history, maybe due to [this bug](https://github.com/lotabout/skim/issues/502) or something else\n- skim might bug in tmux on some system/terminals [bug1](https://github.com/lotabout/skim/issues/482), [bug2](https://github.com/lotabout/skim/issues/412) \n- `toggle-sort` (and `X_SKIM_KEY_SORT_TOGGLE`) doesn't seem to be supported in skim, `ls | sk --bind=pgdn:toggle-sort` also fails\n- to remove extra `?[38;5;26mFOLDER` from output, add `--ansi` to `$SKIM_DEFAULT_OPTIONS` or disable colors in your `$X_SKIM_CMD_FIND`/`DIR` filter (e.g., `fd -t d -c never`)\n- <kbd>\u2388</kbd>/<kbd>\u2387</kbd><kbd>f</kbd> conflict with [xontrib-output-search](https://github.com/anki-code/xontrib-output-search)'s defaults\n\n## Credits\n\nThis package was created with [xontrib template](https://github.com/xonsh/xontrib-template)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "skim (fuzzy finder) integration",
    "version": "0.0.6",
    "project_urls": {
        "Code": "https://github.com/eugenesvk/xontrib-skim",
        "Documentation": "https://github.com/eugenesvk/xontrib-skim/blob/master/ReadMe.md",
        "Homepage": "https://github.com/eugenesvk/xontrib-skim",
        "Issue tracker": "https://github.com/eugenesvk/xontrib-skim/issues",
        "Repository": "https://github.com/eugenesvk/xontrib-skim"
    },
    "split_keywords": [
        "xontrib",
        " xonsh"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0754f3c0f52dd65f39d9daedc50e5fa67de3c50a5fd442869f8ead6800e1c9a7",
                "md5": "f0149c1e03fc8be21afd191a44572387",
                "sha256": "5e29943c485e84eada4bbc79ea9d46e7fc693800c4a1bbece47a96d05318ee32"
            },
            "downloads": -1,
            "filename": "xontrib_skim-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f0149c1e03fc8be21afd191a44572387",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 10255,
            "upload_time": "2024-07-20T12:17:11",
            "upload_time_iso_8601": "2024-07-20T12:17:11.865500Z",
            "url": "https://files.pythonhosted.org/packages/07/54/f3c0f52dd65f39d9daedc50e5fa67de3c50a5fd442869f8ead6800e1c9a7/xontrib_skim-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99b1bede332d114828fbb99b57550ad1f9e4615ff7a3d3b4a55e98fba52ec596",
                "md5": "86260427582592c4294070d00ddcfbdd",
                "sha256": "5f8db8b1ceccfeceae8c38da2728baeb9de4b61a64057d78bfc354b23b1847b0"
            },
            "downloads": -1,
            "filename": "xontrib_skim-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "86260427582592c4294070d00ddcfbdd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 11892,
            "upload_time": "2024-07-20T12:17:29",
            "upload_time_iso_8601": "2024-07-20T12:17:29.699858Z",
            "url": "https://files.pythonhosted.org/packages/99/b1/bede332d114828fbb99b57550ad1f9e4615ff7a3d3b4a55e98fba52ec596/xontrib_skim-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-20 12:17:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eugenesvk",
    "github_project": "xontrib-skim",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "xontrib-skim"
}
        
Elapsed time: 0.30564s