Skip to content

Instantly share code, notes, and snippets.

@rike422
Last active July 29, 2016 10:35
Show Gist options
  • Save rike422/27e0d0b07e9e81292067f81c4908587d to your computer and use it in GitHub Desktop.
Save rike422/27e0d0b07e9e81292067f81c4908587d to your computer and use it in GitHub Desktop.
自分用pecoスクリプト
# http://k0kubun.hatenablog.com/entry/2014/07/06/033336
# http://qiita.com/wada811/items/78b14181a4de0fd5b497
function peco-select-history() {
typeset tac
if which tac > /dev/null; then
tac=tac
else
tac='tail -r'
fi
BUFFER=$(fc -l -n 1 | eval $tac | awk '!a[$0]++' | peco --query "$LBUFFER")
CURSOR=$#BUFFER
zle redisplay
}
function peco-find-file() {
if git rev-parse 2> /dev/null; then
source_files=$(git ls-files)
else
source_files=$(find . -type f)
fi
selected_files=$(echo $source_files | peco --prompt "[find file]")
BUFFER="${BUFFER}${echo $selected_files | tr '\n' ' '}"
CURSOR=$#BUFFER
zle redisplay
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment