refactor fzf file to edit chooser

Changes:
 - Refactored into a function, instead of alias
 - Renamed to fzf_fast_file_edit, in place of ce, which is more
   descriptive
 - Made the code easier to read and edit
This commit is contained in:
Guilherme Rugai Freire 2022-05-15 19:11:26 -03:00
parent 094943b469
commit 442e25b497
No known key found for this signature in database
GPG Key ID: FC05BE5CD322C427

View File

@ -40,9 +40,23 @@ alias config="git --git-dir=\$HOME/.dotfiles/ --work-tree=\$HOME"
alias pacs="pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S"
alias apacs="paru -Slq | fzf --multi --preview 'paru -Si {1}' | xargs -ro paru -S"
# Config/scripts Edit
alias ce="echo \"\$(/bin/ls \$HOME/.scripts/bin | sed \"s|^|\$(realpath \$HOME/.scripts/bin/ --relative-to=.)/|\")\n\$((cd \$HOME && config ls-tree -r master --name-only \$HOME) | sed \"s|^|\$(realpath \$HOME --relative-to=.)/|\" | sed 's|^\./||')\" | fzf --info=inline --prompt='Select a file: ' --preview='bat --paging=never --style=plain --color=always {}' | xargs -r \$(echo \$EDITOR)"
bindkey -s '^[^E' 'ce\n'
fzf_fast_file_edit() {
# Get scripts
scripts="$(/bin/ls "$HOME/.scripts/bin" | sed "s|^|$(realpath "$HOME"/.scripts/bin/ --relative-to=.)/|")"
# Get config files
current_branch="$(config rev-parse --abbrev-ref HEAD)"
config_files="$(config ls-tree -r "$current_branch" --name-only "$HOME")"
# Select file
selected_file=$(printf "%s\n%s" "$scripts" "$config_files" | fzf --info=inline --prompt='Select a file: ' --preview='bat --paging=never --style=plain --color=always {}')
if [ -n "$selected_file" ]; then
$EDITOR "$selected_file"
fi
}
bindkey -s '^[^E' 'fzf_fast_file_edit\n'
# Alias for python3
alias python="python3"