#! /bin/bash
branches=$( git branch --all | grep -v HEAD) &&
branch=$( echo " $branches " |
fzf -d $(( 2 + $(wc - l <<< "$branches ") )) +m) &&
git checkout $( echo " $branch " | sed " s/.* //" | sed " s#remotes/[^/]*/##" )
list ssh hosts from ssh config
function ssh() {
if [[ $# -eq 0 ]]; then
local host
host=$( \g rep ' ^Host ' ~ /.ssh/config | awk ' {print $2}' | fzf --prompt=' Select SSH host: ' )
if [[ -n " $host " ]]; then
command ssh " $host "
fi
else
command ssh " $@ "
fi
}
function search() {
local selection=$( fd --hidden --type f --type d | fzf --preview ' ([[ -d {} ]] && echo "📁" || bat -n --color=always {} 2> /dev/null)' --preview-window=right:40%)
if [ -z " $selection " ]; then
return
elif [ -f " $selection " ]; then
vim selection"
elif [ -d " $selection " ]; then
cd " $selection "
else
echo " Invalid selection"
fi
}
um why'd i make this one, it seems similar as previous?
function vfd() {
local files=" $( fd --fixed-strings " ${1} " ) "
local amount=$( echo " ${files} " | wc -l)
if [[ -z " ${files} " ]]; then
echo " No matches"
return 1
elif [[ " ${amount} " -gt 1 ]]; then
local select
select=" $( echo " ${files} " | grep --invert-match ' \.sw[op]' | fzf) "
if [[ -n " ${select} " ]]; then
[[ -f ~ /.zsh_history ]] && echo " vim \" ${select} \" " >> ~ /.zsh_history
[[ -f ~ /.histfile ]] && echo " vim \" ${select} \" " >> ~ /.histfile
[[ -f ~ /.bash_history ]] && echo " vim \" ${select} \" " >> ~ /.bash_history
vim " ${select} "
cd " $( dirname ${select} ) "
return 0
else
return 1
fi
fi
}