If your editor does not provide an option for that you could write a function like that one:
kate~(){ cp "${!#}" "${!#}~" && kate $@ ;}
You can do that for every editor, this simply takes the last argument (${!#}
), which always should be the filename, makes a copy of it and runs the editor (kate
) with the whole argument line ($@
). This example function is called with kate~ [OPTIONS] [FILE]
. Functions like that are best stored in the ~/.bash_aliases
file, this way they are effective for every new opened terminal.
To test for a specific directory like /etc/
you could do e.g.
kate~(){ [[ "${!#}" =~ /etc/ ]] && cp "${!#}" "${!#}~" ; kate $@ ;}
This way the backup file will only be created if the file to open is located under /etc/
.