Add chext zsh function

This commit is contained in:
Marko Korhonen 2023-07-11 14:23:13 +03:00
parent db136a7313
commit e0a026afb3
Signed by: FunctionalHacker
GPG key ID: A7F78BCB859CD890
2 changed files with 29 additions and 0 deletions

0
home/.config/asd Normal file
View file

View file

@ -300,3 +300,32 @@ clock() {
sleep 0.1
done
}
# Change file extension made easy
chext() {
file="$1"
new_ext="$2"
dest="${file%.*}.$new_ext"
help() {
printf "Change file extension\nUsage: chext file new_extension\nFor example: chext my_script.sh zsh"
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
help
return
fi
if [ $# -lt 2 ]; then
help
return 1
fi
if [ ! -e "$1" ]; then
echo "$file: no such file or directory"
help
return 1
fi
mv "$file" "$dest"
}