Skip to content

Instantly share code, notes, and snippets.

@mlebkowski mlebkowski/README.md
Last active May 6, 2016

Embed
What would you like to do?
Choose one of the parent directories to change to

up

Interactively choose one of the parent dirs to change to.

Requirements & Installation

  1. Install percol
  2. Setup your shell to load the up function at startup
  • In fish use funced up, paste contents, funcsave up
  • In bash paste it in .bashrc or any other file and source it from .bashrc

Usage

Just call up and select one of the parent directories. Ctrl+C cancels.

preview

By default, a directory containing a .env subdirectory will be selected. You may override the way the default directory is chosen by replacing the _up_test_main_dir function

_up_test_main_dir() {
test -d "$1/.env"
}
up() {
local pwd="$(dirname "$(pwd)")"
local current=0 idx=$(while [ "/" != "$pwd" ]; do
if _up_test_main_dir "$pwd"; then
echo $current
break;
fi
current=$((current + 1))
pwd="$(dirname "$pwd")"
done)
local dir=$(while [ "/" != "$pwd" ]; do
echo $pwd
pwd="$(dirname "$pwd")"
done | percol --initial-index $idx)
if [ ! -d "$dir" ]; then
return;
fi
cd "$dir"
}
function up
set -l current 0
set -l idx 0
set -l pwd (dirname (pwd))
set dirs (while [ "/" != "$pwd" ];
echo $pwd
if [ -d "$pwd/.env" ];
set idx $current
end
set current (math $current + 1)
set pwd (dirname "$pwd")
end)
for line in $dirs;
echo $line
end | percol --initial-index $idx | read -l dir
if [ ! -d "$dir" ];
return
end;
cd "$dir"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.