Topic: https://brettterpstra.com/2014/05/14/up-fuzzy-navigation-up-a-directory-tree/
hide preview

What's next? verify your email address for reply notifications!

Keith Rollin 11y, 47d ago

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/")
}

hide preview

What's next? verify your email address for reply notifications!

Aaron Bach 11y, 49d ago

Sidenote: speaking of bashmarks... Not sure it's under active maintenance anymore. :( It has a few important pull requests lingering.

hide preview

What's next? verify your email address for reply notifications!

Patrick Ahles 11y, 50d ago

Your sentaku link is not quite correct...

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 50d ago

Argh. SearchLink and lack of sleep...

hide preview

What's next? verify your email address for reply notifications!

Robert Audi 11y, 50d ago

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')"`

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 50d ago

Tested and fixed, thanks!

hide preview

What's next? verify your email address for reply notifications!

Bernd Goldschmidt 11y, 50d ago

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))'

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 50d ago

That's great. Thanks!

hide preview

What's next? verify your email address for reply notifications!