├── .gitignore ├── README.md ├── cool-peco ├── cool-peco-demo.gif ├── cool-poco.jpg ├── customs └── cool-peco-custom-example ├── functions ├── cool-peco-aws-ec2-instances ├── cool-peco-filename-search ├── cool-peco-ghq ├── cool-peco-git-checkout ├── cool-peco-git-log ├── cool-peco-git-status ├── cool-peco-history ├── cool-peco-ps ├── cool-peco-ssh └── cool-peco-tmux-session ├── install.sh └── utils └── _cool-peco-insert-command-line /.gitignore: -------------------------------------------------------------------------------- 1 | customs/* 2 | !customs/cool-peco-custom-example 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cool peco 2 | 3 | [peco](https://github.com/peco/peco) utils. 4 | 5 | ## Functions 6 | 7 | - cool-peco-filename-search 8 | - cool-peco-ghq 9 | - cool-peco-git-checkout 10 | - cool-peco-git-log 11 | - cool-peco-history 12 | - cool-peco-ps 13 | - cool-peco-ssh 14 | - cool-peco-tmux-session 15 | - cool-peco-aws-ec2-instances 16 | 17 | ![demo](./cool-peco-demo.gif) 18 | 19 | ## Install 20 | 21 | ``` 22 | CPDIR=~/ 23 | cd $CPDIR 24 | git clone https://github.com/ryoppy/cool-peco.git 25 | cd cool-peco 26 | sh ./install.sh 27 | ``` 28 | 29 | and re-login. 30 | 31 | ## Usage 32 | 33 | ``` 34 | $ cool-peco- 35 | ``` 36 | 37 | ## Alias 38 | 39 | keybind or alias 40 | 41 | add ~/.zshrc 42 | 43 | ``` 44 | bindkey '^r' cool-peco-history # ctrl+r 45 | ``` 46 | 47 | or 48 | 49 | ``` 50 | alias hist=cool-peco-history 51 | ``` 52 | 53 | ## Setting examples 54 | 55 | add ~/.zshrc 56 | 57 | ``` 58 | bindkey '^r' cool-peco-history # ctrl+r 59 | bindkey '^h' cool-peco-ssh 60 | bindkey '^p' cool-peco-ps 61 | 62 | alias ff=cool-peco-filename-search 63 | alias gbb=cool-peco-git-checkout 64 | alias gll=cool-peco-git-log 65 | alias ta=cool-peco-tmux-session 66 | alias cg=cool-peco-ghq 67 | ``` 68 | 69 | 70 | ## Add custom functions 71 | 72 | If you wanna add new function, just add to `./customs` directory. 73 | 74 | ``` 75 | $ cp ./customs/cool-peco-custom-example ./customs/cool-peco-custom-new 76 | ``` 77 | 78 | and re-login. 79 | 80 | ``` 81 | $ cool-peco-custom-new 82 | ``` 83 | 84 | use alias? 85 | 86 | ``` 87 | bindkey '^e' cool-peco-custom-new # ctrl+e 88 | # or 89 | alias cn=cool-peco-custom-new 90 | ``` 91 | 92 | `./customs/*` is contains `.gitignore`. 93 | 94 | ## Why "cool" peco 95 | 96 | "cool poco" is japanese comedian. ヾ(⌒(ノ'ω')ノ 97 | 98 | ![クールポコ](./cool-poco.jpg) 99 | -------------------------------------------------------------------------------- /cool-peco: -------------------------------------------------------------------------------- 1 | function() { 2 | for dir in ${^fpath}/../cool-peco/{utils,functions,customs}(N-/); do 3 | FPATH=$FPATH:$dir 4 | done 5 | autoload -Uz _cool-peco-insert-command-line 6 | 7 | local file f 8 | for file in ${^fpath}/../cool-peco/{utils,functions,customs}/*(N-.); do 9 | f=$(basename $file) 10 | autoload -Uz $f 11 | zle -N $f 12 | done 13 | } 14 | 15 | # for backward compability. 16 | function cool-peco() {} 17 | -------------------------------------------------------------------------------- /cool-peco-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ryoppy/cool-peco/fb61563f0f61e9fee7a1e5b64a85323824a479ac/cool-peco-demo.gif -------------------------------------------------------------------------------- /cool-poco.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ryoppy/cool-peco/fb61563f0f61e9fee7a1e5b64a85323824a479ac/cool-poco.jpg -------------------------------------------------------------------------------- /customs/cool-peco-custom-example: -------------------------------------------------------------------------------- 1 | local result=$(ls | peco) 2 | 3 | if [ -n "$result" ]; then 4 | _cool-peco-insert-command-line "file '$result'" 5 | fi 6 | -------------------------------------------------------------------------------- /functions/cool-peco-aws-ec2-instances: -------------------------------------------------------------------------------- 1 | local row=$(aws --profile=my ec2 describe-instances | jq -r '.Reservations[] | .Instances[] | [.PrivateIpAddress,.InstanceId, (.Tags[] | select(.Key == "Name") | .Value)] | join("\t")' | peco) 2 | local result=$(echo "$row" | awk '{print $2}') 3 | 4 | if [ -n "$result" ]; then 5 | _cool-peco-insert-command-line $result 6 | fi 7 | -------------------------------------------------------------------------------- /functions/cool-peco-filename-search: -------------------------------------------------------------------------------- 1 | ## 2 | # file name search 3 | # 4 | local res 5 | res=$(find . -name "*${1}*" | grep -v "/\." | peco) 6 | _cool-peco-insert-command-line $res 7 | -------------------------------------------------------------------------------- /functions/cool-peco-ghq: -------------------------------------------------------------------------------- 1 | ## 2 | # select git repository by ghq command 3 | # 4 | local res 5 | res=$(ghq list | peco --query "$LBUFFER") 6 | if [ -n "$res" ]; then 7 | _cool-peco-insert-command-line "cd $(ghq root)/$res" 8 | fi 9 | -------------------------------------------------------------------------------- /functions/cool-peco-git-checkout: -------------------------------------------------------------------------------- 1 | ## 2 | # select branch, and checkout 3 | # 4 | local res 5 | local branch=$(git branch -a | peco | tr -d ' ') 6 | if [ -n "$branch" ]; then 7 | if [[ "$branch" =~ "remotes/" ]]; then 8 | local b=$(echo $branch | awk -F'/' '{for(i=3;i /dev/null 2>&1; then 7 | tailr="tac" 8 | fi 9 | res=$(fc -l -n 1 | eval $tailr | peco) 10 | _cool-peco-insert-command-line $res 11 | -------------------------------------------------------------------------------- /functions/cool-peco-ps: -------------------------------------------------------------------------------- 1 | ## 2 | # select pid by `ps aux` 3 | # 4 | local res 5 | res=$(ps aux | peco | awk '{print $2}') 6 | _cool-peco-insert-command-line $res 7 | -------------------------------------------------------------------------------- /functions/cool-peco-ssh: -------------------------------------------------------------------------------- 1 | ## 2 | # select ssh host from ~/.ssh/config 3 | # 4 | local res 5 | res=$(grep "Host " ~/.ssh/config | grep -v '*' | cut -b 6- | peco) 6 | if [ -n "$res" ]; then 7 | _cool-peco-insert-command-line "ssh $res" 8 | fi 9 | -------------------------------------------------------------------------------- /functions/cool-peco-tmux-session: -------------------------------------------------------------------------------- 1 | ## 2 | # select tmux session 3 | # 4 | local res 5 | res=$(tmux list-sessions | peco | awk -F':' '{print $1}') 6 | if [ -n "$res" ]; then 7 | _cool-peco-insert-command-line "tmux attach -t $res" 8 | fi 9 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | 3 | set -e 4 | 5 | _cool_peco_init_script=$( 6 | cat < ' 18 | read 19 | case "$REPLY" in 20 | y) 21 | echo "$_cool_peco_init_script" >> ~/.zshrc 22 | echo "Complete!" 23 | ;; 24 | *) 25 | echo "You can copy following script, and paste to zsh load file. (maybe ~/.zshrc.local? ~/.zshrc.custom?)" 26 | echo "$_cool_peco_init_script" 27 | ;; 28 | esac 29 | 30 | -------------------------------------------------------------------------------- /utils/_cool-peco-insert-command-line: -------------------------------------------------------------------------------- 1 | if zle; then 2 | BUFFER=$1 3 | CURSOR=$#BUFFER 4 | zle clear-screen 5 | else 6 | print -z $1 7 | fi 8 | --------------------------------------------------------------------------------