From 3d6656a160ec511097752f89193e80aaeb913a02 Mon Sep 17 00:00:00 2001 From: q Date: Wed, 22 Mar 2017 20:17:51 +0200 Subject: [PATCH] ncd, the Next cd --- qcd_function | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/qcd_function b/qcd_function index 7649f10..934c5f4 100644 --- a/qcd_function +++ b/qcd_function @@ -281,6 +281,37 @@ sys.stderr.write(os.path.join(pat_dir,key_match)) ' "$@" 2>&1 1>&$out); } {out}>&1 ; \cd "$cdto" } +function ncd() { + # Next cd: cd to ../[next_folder]. ncd - to go to previous + local _current_pwd _iter_d _iter_prev _current_found + _current_pwd=$( basename $( pwd ) ) + \cd .. + for _iter_d in *; do + if [ ! -d "$_iter_d" ]; then continue; fi + if [ -n "$_current_found" ]; then + \cd "$_iter_d" + return + fi + if [ "$_iter_d" = "$_current_pwd" ]; then + _current_found=true + if [ "$1" = "-" ]; then + if [ -z "$_iter_prev" ]; then + echo $_current_pwd was the first folder. + else + \cd "$_iter_prev"; + return + fi + fi + fi + _iter_prev="$_iter_d" + done + if [ -n "$_current_found" ]; then + echo "$_current_pwd" was the last folder. + else + echo "$_current_pwd" was not found in ../ + fi +} + function rmv () { # mv files/folders with rsync (shows speed and progress) local sources