diff --git a/.zsh_aliases b/.zsh_aliases index 1cfc7a5..3f85de5 100644 --- a/.zsh_aliases +++ b/.zsh_aliases @@ -15,3 +15,51 @@ alias edis='expressvpn disconnect' alias aws1='ssh ubuntu@ec2-18-196-102-236.eu-central-1.compute.amazonaws.com' alias gcp='gcloud compute ssh instance-1' alias blist='borg list ssh://borg@docker1.home.hartzan.com:2222/backup/arch' + +fzf_find_edit() { + local file=$( + fzf --no-multi --preview 'bat --color=always --line-range :500 {}' + ) + if [[ -n $file ]]; then + $EDITOR $file + fi +} + +alias ffe='fzf_find_edit' + +fda() { + local dir + dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir" + } + +alias fcd='fda' + +fzf_grep_edit(){ + if [[ $# == 0 ]]; then + echo 'Error: search term was not provided.' + return + fi + local match=$( + rg --color=never --line-number "$1" | + fzf --no-multi --delimiter : \ + --preview "bat --color=always --line-range {2}: {1}" + ) + local file=$(echo "$match" | cut -d':' -f1) + if [[ -n $file ]]; then + $EDITOR $file +$(echo "$match" | cut -d':' -f2) + fi +} + +alias fge='fzf_grep_edit' + +fzf_kill() { + local pids=$( + ps -f -u $USER | sed 1d | fzf --multi | tr -s [:blank:] | cut -d' ' -f3 + ) + if [[ -n $pids ]]; then + echo "$pids" | xargs kill -9 "$@" + fi +} + +alias fkill='fzf_kill' + diff --git a/.zshrc b/.zshrc index 246e3d1..eba6890 100644 --- a/.zshrc +++ b/.zshrc @@ -111,6 +111,7 @@ export BROWSER=/usr/bin/google-chrome-stable #fzf export FZF_CTRL_R_OPTS='--sort --exact' export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'" +export FZF_DEFAULT_COMMAND='fd --type f --hidden' # Compilation flags export ARCHFLAGS="-arch x86_64"