4 ms·
Every 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 f
by eponeponepon 13y ago
Every 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)