Created
August 3, 2025 14:15
-
-
Save adam-currie/5f07d00e4b4f80542d37c5eb0fd0a241 to your computer and use it in GitHub Desktop.
fish functions that wrap cp/mv for backup/restore of files/directories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function _bak_help | |
| echo "Usage: bak|unbak <file/dir> [suffix]" | |
| echo " bak: Copy <file/dir> to <file/dir><suffix> (default: .bak)" | |
| echo " unbak: Copy <file/dir><suffix> to <file/dir> (default: .bak)" | |
| end | |
| function bak | |
| if test "$argv[1]" = "-h" | |
| _bak_help | |
| return | |
| end | |
| set -l file $argv[1] | |
| set -lq suffix $argv[2] | |
| or set -l suffix '.bak' | |
| set -l bakfile $file$suffix | |
| cp -ri $file $bakfile | |
| end | |
| function unbak | |
| if test "$argv[1]" = "-h" | |
| _bak_help | |
| return | |
| end | |
| set -l file $argv[1] | |
| set -lq suffix $argv[2] | |
| or set -l suffix '.bak' | |
| set -l bakfile $file$suffix | |
| if test -e $bakfile | |
| mv $bakfile $file | |
| else | |
| echo "Backup file does not exist: $bakfile" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment