From 64ca1b72f98abdd3fb14e65485017989fc54eefa Mon Sep 17 00:00:00 2001 From: druckdev Date: Fri, 23 Jul 2021 12:10:31 +0200 Subject: [PATCH] zsh: Move `{,un}bkp` from aliases to functions Since both were functions already their place seems more appropriate in functions.zsh. This also fixes the completion of both, since they did not complete files before. Other changes in `unbkp`: - Use `mv` instead of `cp` - Fix little typo (forgotten quote) and support specifying the original name instead of only the backup. - Do not "rename" the file if there is no change in name (Leading to the prompt if the file should be overwritten) --- .config/zsh/zshrc.d/30-alias.zsh | 4 ---- .config/zsh/zshrc.d/40-functions.zsh | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.config/zsh/zshrc.d/30-alias.zsh b/.config/zsh/zshrc.d/30-alias.zsh index cb5725a..ce579aa 100644 --- a/.config/zsh/zshrc.d/30-alias.zsh +++ b/.config/zsh/zshrc.d/30-alias.zsh @@ -99,10 +99,6 @@ alias lowres='() { xrandr -s 1920x1080; $1 "${@[2,-1]}"; xrandr -s 3200x1800 }' - # Create copy with .bkp extension - alias bkp='() { for f; do command cp -i "$f"{,.bkp}; done }' - # Reverse bkp() - alias unbkp='() { for f; do command cp -i "$f" "${f%.bkp}; done }' # Grep in history file alias histgrep='() { grep "$@" "${HISTFILE:-$HOME/.zsh_history}" }' # URL-encode diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index 159df90..92631e0 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -432,3 +432,21 @@ git-rebase-add-stash() { git add -u && git rebase --continue } + +# Create copy with a .bkp extension +bkp() { + for f; do + command cp -i "$f"{,.bkp} + done +} + +# Reverse bkp() +unbkp() { + for f; do + if [[ ${f%.bkp} != $f ]]; then + command mv -i "$f" "${f%.bkp}" + elif [[ -e $f.bkp ]]; then + command mv -i "$f.bkp" "$f" + fi + done +}