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)
This commit is contained in:
2021-07-23 12:10:31 +02:00
parent ca5edbe538
commit 64ca1b72f9
2 changed files with 18 additions and 4 deletions

View File

@@ -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
}