Skip to content

Instantly share code, notes, and snippets.

@elhenro
Last active January 24, 2023 21:56
Show Gist options
  • Save elhenro/068573517bdf17e63b15285c5e63b515 to your computer and use it in GitHub Desktop.
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!)
# .. 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
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