Archive

Posts Tagged ‘zsh’

zsh magic

April 6th, 2013 No comments

sometimes you need to copy a file in a remote directory (like backing up a config file).
If its not in your current working directory, then you can end up with silliness like

cp /usr/src/linux/arch/x86/boot/bzImage /usr/src/linux/arch/x86/bzImage.backup

-lots of duplication. I’ve been trying to find a better way for years but never found it.

Khayyam in #Gentoo cracked it within moments of me asking (after setting me onto zsh (a different shell to bash))
with zsh you can do the clever thing of:

echo /usr/src/linux/arch/x86/boot/bzImage !#1.copy


which auto-expands to

/usr/src/linux/arch/x86/boot/bzImage /usr/src/linux/arch/x86/bzImage.backup

massive thanks to Khayyam who also has some immense .zsh customization & scripts on the go. He also suggests that you check out http://zshwiki.org for more excellent tips :)

edit: in bash you can just do cp /path/to/file.png{,.old}

Categories: zsh Tags: ,