Hi Brett. I don't have Ruby installed, so I came up with a version that used `sed` instead. Here's a breakdown of what the function does:
* Strips white spaces from the input parameter. * Converts input parameter to have [^/]* after every character. * Uses the resulting pattern to find a match between two /'s (while also prefixing the pattern with [^/]*). * If a match is found, return everything up to the end of the match, stripping off any trailing test.
function _up() { local rx rx=$(echo "$1" | sed -e "s/\s\+//g" -e "s/\(.\)/\1[^\/]*/g") echo -n $(pwd | sed -e "s/\(.*\/[^\/]*${rx}\)\/.*/\1/") }
Here is an improvement for gt our sysadmin wrote to avoid jumping to ~ if you are not within a git repository and to avoid strange output on opening a terminal:
alias gt='cd $(git rev-parse --show-toplevel 2>/dev/null || (echo "."; echo "Not within a git repository" >&2))'
Comments
Hi Brett. I don't have Ruby installed, so I came up with a version that used `sed` instead. Here's a breakdown of what the function does:
* Strips white spaces from the input parameter.
* Converts input parameter to have [^/]* after every character.
* Uses the resulting pattern to find a match between two /'s (while also prefixing the pattern with [^/]*).
* If a match is found, return everything up to the end of the match, stripping off any trailing test.
function _up()
{
local rx
rx=$(echo "$1" | sed -e "s/\s\+//g" -e "s/\(.\)/\1[^\/]*/g")
echo -n $(pwd | sed -e "s/\(.*\/[^\/]*${rx}\)\/.*/\1/")
}
export
Sidenote: speaking of bashmarks... Not sure it's under active maintenance anymore. :( It has a few important pull requests lingering.
export
Your sentaku link is not quite correct...
export
Argh. SearchLink and lack of sleep...
export
If used with ZSH, there will be an error with this line:
updir=`echo $PWD | ruby -e "print STDIN.read.sub(/(.*\/$rx[^\/]*\/).*/i,'\1')"`
To fix it, you need to surround $rx with curly braces:
updir=`echo $PWD | ruby -e "print STDIN.read.sub(/(.*\/${rx}[^\/]*\/).*/i,'\1')"`
export
Tested and fixed, thanks!
export
Here is an improvement for gt our sysadmin wrote to avoid jumping to ~ if you are not within a git repository and to avoid strange output on opening a terminal:
alias gt='cd $(git rev-parse --show-toplevel 2>/dev/null || (echo "."; echo "Not within a git repository" >&2))'
export
That's great. Thanks!
export