4 ms·
I have a similar script[0] that I use quickly cd to projects that I work on frequently. I maintain a ~/.projects file which is a space seperated value file with
by samwilliams 13y ago
I have a similar script[0] that I use quickly cd to projects that I work on frequently. I maintain a ~/.projects file which is a space seperated value file with pairs of name and location. Then I just use 'project worldpeacexyz' to go to the appropriate directory.
[0] Here is the one liner...
cd $(awk -v proj=$1 '$1 == proj { print $2; }' ~/.projects)
- eponeponepon 13y agoEvery so often I see a one-liner like this and think to myself that I really must sit down and learn awk properly. I never do though. In the meantime, thanks for that - I'm pinching it! :)
- samwilliams 13y agoHappy to help! I am certainly not a master of bash/awk/sed scripting but I do find the ability to express very complex file operations in minimal characters very rewarding :). You will probably have to alias the script[0], as cd'ing in the script won't change the outside environment by default. I cut out a 'function' to make it one line, but I have attached the full source[1]. If you don't pass it any arguments it will tell you all of the available projects :). [0] Add something like this to your .bashrc alias project='. project' [1] The full source: #!/bin/bash if [[ $# -eq 0 ]] ; then awk '{print $1;}' ~/.projects exit 0 fi cd $(awk -v proj=$1 '$1 == proj { print $2; }' ~/.projects)