I'm creating a library in the C language and have separate folders for each header/source file. I recently had the need to go into many of the folders and change some code in both the .c and .h files. So I'm frequently using the commands:
nano <some-detailed-filename.c>
nano <some-detailed-filename.h>
I wanted to look at creating an alias like the following:
alias nanc="nano $(ls ./*.c)"
alias nanh="nano $(ls ./*.h)"
The idea being that it will open whatever .c/.h files in the current directory. But when I add these lines to my .zshrc file, I get the following as the aliases:
# alias nanc
nanc='nano ./xh.c ./yp.c'
# alias nanh
nanh='nano ./xh.h ./yp.h'
This is not desired, as the files nano tries to open are only located in my home/login directory.
How can I go about creating this alias so that it uses the current directory I'm in when I issue the command? I'm not having much luck with my searches.
Don't use double-quotes in the assignment; use single-quotes. If you use double-quotes, the value is substituted immediately.
By the way, there is another problem with your alias: the ls command will expand any wildcards which happen to be directory names (it is perfectly legal for a directory to have a name ending with ".c"). To guard against extra-odd results from that, you might want to use the "-d" option, e.g.,
alias nanc='nano $(ls -d ./*.c)'
However, even the ls is redundant. This works for me:
alias nanc='nano *.c'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With