Skip to content

Instantly share code, notes, and snippets.

@jameshfisher
Created April 3, 2023 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshfisher/96ff5264fb91a62e1c024133d0c8277a to your computer and use it in GitHub Desktop.
Save jameshfisher/96ff5264fb91a62e1c024133d0c8277a to your computer and use it in GitHub Desktop.
Shell function to rename file with filename editor
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