Skip to content

Instantly share code, notes, and snippets.

@patorash

patorash/peco.fish

Last active Feb 13, 2019
Embed
What would you like to do?
peco.fish
function peco_kill --description="Kill selected process by peco"
if set -q $argv
ps aux | peco | read proc
else
ps aux | peco --query $argv | read proc
end
if test -n "$proc"
set -l pid (echo $proc | awk '{print $2}')
echo "kill pid: $pid. [$proc]"
kill $pid
end
set -e proc
end
function peco_select_repository --description="Select repository by ghq & peco"
if set -q $argv
ghq list -p | peco | read line; builtin cd $line
else
ghq list -p | peco --query $argv | read line; builtin cd $line
end
set -e line
end
alias select_repository "peco_select_repository"
function peco_select_history --description="Select history by peco"
if set -q $argv
history | peco | read line; commandline $line
else
history | peco --query $argv | read line; commandline $line
end
set -e line
end
bind \cr peco_select_history
function peco_delete_branch --description="Delete selected branch by peco"
git branch | peco | read line
set -l branch_name (echo $line | awk '{print $1}')
if test -n "$branch_name"
if test "$branch_name" != "*"
git branch -d $branch_name
else
echo "Can't delete current branch."
end
end
end
alias delete_branch "peco_delete_branch"
function peco_select_branch --description="Select selected branch by peco"
git branch | peco | read line
set -l branch_name (echo $line | awk '{print $1}')
if test -n "$branch_name"
if test "$branch_name" != "*"
git co $branch_name
else
echo "Can't select current branch."
end
end
end
alias select_branch "peco_select_branch"
function peco_rspec --description="Run selected rspec by peco"
find . -follow -name "*_spec.rb" | peco | read line
if test -n "$line"
commandline "bin/rspec $line"
end
set -e line
end
function peco_pipe_rspec
peco | read line
if test -n "$line"
commandline "bin/rspec $line"
end
set -e line
end
function peco_ssh
awk '
tolower($1)=="host" {
for(i=2;i<=NF; i++) {
if ($i !~ "[*?]") {
print $i
}
}
}
' ~/.ssh/config | sort | peco | read line
if test -n "$line"
ssh $line
end
set -e line
end
alias s "peco_ssh"
function peco_rake_task --description="Select rake task by peco"
bin/rake -T | peco | read line
if test -n "$line"
set -l task_name (echo $line | awk '{print $2}')
commandline "bin/rake $task_name"
end
set -e line
end
alias rt "peco_rake_task"
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.