Skip to content

Instantly share code, notes, and snippets.

@piroor
Last active November 8, 2018 01:02
Show Gist options
  • Save piroor/3938d4356cf881b01bf381bd76191a40 to your computer and use it in GitHub Desktop.
Save piroor/3938d4356cf881b01bf381bd76191a40 to your computer and use it in GitHub Desktop.
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