I have this alias in my bashrc:
alias qn="cd ~/docs/org/0-inbox/ && vim `date +%Y-%m-%d-%H%M`.md"
which uses Command-Substitution1 and basically just makes a “quick note” which I can refer later and move it a more appropriate place in my organized notes when I have the time. But when I run this alias it always opens the same note even if I run it at another time.
TIL that using ` (backticks) or even $()
in alias this way makes it output
the value when the alias is initialized. So it essentially freezes it’s value
when the alias is first sourced. So, If I run this command again at another
time it will still open the same file. Not what is intended.
The solution? Escape the command substitution
alias qn="cd ~/docs/org/0-inbox/ && vim \`date +%Y-%m-%d-%H%M\`.md"
Or
alias qn="cd ~/docs/org/0-inbox/ && vim \$(date +%Y-%m-%d-%H%M).md"
While I am at it let’s not cd into the directory shall we?
alias qn="vim ~/docs/org/0-inbox/\$(date +%Y-%m-%d-%H%M).md"