Created
April 3, 2023 16:53
-
-
Save jameshfisher/96ff5264fb91a62e1c024133d0c8277a to your computer and use it in GitHub Desktop.
Shell function to rename file with filename editor
This file contains 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
rename() { | |
[ "$#" -ne 1 ] && echo "Usage: rename <file_path>" && return 1 | |
local temp_file=$(mktemp) | |
echo "$1" > "$temp_file" | |
"${EDITOR:-vi}" "$temp_file" | |
local new_path=$(cat "$temp_file") | |
mv "$1" "$new_path" | |
echo "$new_path" | |
rm "$temp_file" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment