Last active
January 24, 2023 21:56
-
-
Save elhenro/068573517bdf17e63b15285c5e63b515 to your computer and use it in GitHub Desktop.
zsh ctrl+x shortcut to select scripts to paste into command line (without executing!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .. put into ~/.zshrc | |
# to extend directories, symlinks can be created in ~/scripts/.. (`ln -s`) | |
fzf-paste-input() { | |
location=$(pwd) | |
cd ~/scripts | |
local output | |
# basic | |
#output=~/scripts/$(fzf</dev/tty) && LBUFFER+=${(q-)output} | |
# with preview | |
output=~/scripts/$(fzf --preview 'bat --theme gruvbox-light --style=numbers --color=always --line-range :500 {}'</dev/tty) && LBUFFER+=${(q-)output} | |
cd $location | |
} | |
zle -N fzfPasteInput | |
bindkey "^X" fzfPasteInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fzfPasteInput() { | |
location=$(pwd) | |
cd ~/scripts | |
local output | |
output=$(fzf --print0 < /dev/tty | xargs -0 -I % echo -n "~/scripts/%" | sed "s|$location/||") | |
output="${output%\"}" # remove the last character from the string, which is the closing quote | |
output="${output#\"}" # remove the first character from the string, which is the opening quote | |
output="${output% }" # remove the last character from the string, which is the space | |
LBUFFER+="${output}" | |
cd $location | |
} | |
zle -N fzfPasteInput | |
bindkey "^X" fzfPasteInput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment