Skip to content

Instantly share code, notes, and snippets.

@piroor piroor/peco-commands.sh
Last active Nov 8, 2018

Embed
What would you like to do?
Predefined commands based on peco (on Bash)
# Usage:
# 1. Download latest binary of peco from: https://github.com/peco/peco/releases
# 2. Extract "peco" from the downloaded archive and put it to somewhere listed in $PATH.
# 3. Put this file as "~/peco-commands.sh".
# 4. Add a line "source ~/peco-commands.sh".
# 5. Exit and login again.
# from http://bio-eco-evo.hatenablog.com/entry/2017/04/30/044703
peco-cd() {
local sw="1"
while [ "$sw" != "0" ]
do
if [ "$sw" = "1" ];then
local list=$(echo -e "---$PWD\n../\n$( ls -F | grep / )\n---Show hidden directory\n---Show files, $(echo $(ls -F | grep -v / ))\n---HOME DIRECTORY")
elif [ "$sw" = "2" ];then
local list=$(echo -e "---$PWD\n$( ls -a -F | grep / | sed 1d )\n---Hide hidden directory\n---Show files, $(echo $(ls -F | grep -v / ))\n---HOME DIRECTORY")
else
local list=$(echo -e "---BACK\n$( ls -F | grep -v / )")
fi
local slct=$(echo -e "$list" | peco )
if [ "$slct" = "---$PWD" ];then
local sw="0"
elif [ "$slct" = "---Hide hidden directory" ];then
local sw="1"
elif [ "$slct" = "---Show hidden directory" ];then
local sw="2"
elif [ "$slct" = "---Show files, $(echo $(ls -F | grep -v / ))" ];then
local sw=$(($sw+2))
elif [ "$slct" = "---HOME DIRECTORY" ];then
cd "$HOME"
elif [[ "$slct" =~ / ]];then
cd "$slct"
elif [ "$slct" = "" ];then
:
else
local sw=$(($sw-2))
fi
done
}
peco-git() {
local command="$1"
local branch
case "$command" in
checkout )
branch="$(git branch | peco | sed -r 's/^[\* ]*//')"
[ "$branch" != '' ] && git checkout "$branch"
;;
esac
}
alias cd?='peco-cd'
alias ls?='(peco-cd; ls)'
alias ls-la?='(peco-cd; ls -la)'
alias git?='peco-git'
alias unar?='unar $(ls | peco)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.