Skip to content

Latest commit

 

History

History
156 lines (121 loc) · 3.15 KB

README.md

File metadata and controls

156 lines (121 loc) · 3.15 KB

Bash dir stacking/bookmarking made easy.

##Why?

Because you need it.

dirStack is z for current session. So you use z for that path you entered thousand times the last 4 years and use dirStack for your n last entered dirs on that session.

##INSTALL

$cd ~/yourDir
$git clone https://github.com/liloman/dirStack.git 
try it on-fly
$source dirStack/dirStack.sh
or 
$echo ". ~/yourDir/dirStack/dirStack.sh"  >> ~/.bashrc 

##Use

cd into directories and when you lost a directory from "cd -" it will be added to your dirStack automagically effortlessly.

So:

$source dirStack/dirStack.sh
✪ Empty dir stack(a add,d delete,g go number,~num = dir)
$cd /tmp
✪ Empty dir stack(a add,d delete,g go number,~num = dir)
$cd /var
✪ Empty dir stack(a add,d delete,g go number,~num = dir)
$ cd log/
✪ [1:/tmp]
$ cd journal/
✪ [1:/var][2:/tmp]
$ cd ~
✪ [1:/var/log][2:/var][3:/tmp]
$ls ~2/
dm    crash  empty  gopher 
...
✪ [1:/var/log][2:/var][3:/tmp]
$cp -rv ~3/ ~1/dm 
✪ [1:/var/log][2:/var][3:/tmp]
$g 3
Changed dir to /tmp
✪ [1:/var/log][2:/var][3:/tmp]
$pwd
/tmp

dirStack working

##FAQ

###Can I go/add/delete a dirStack?

Absolutely!

It includes the bash aliases (g,a,d).

✪ [1:/var/log][2:/var][3:/tmp]
$d 2
Deleted /var from dir stack
✪ [1:/var/log][2:/tmp]
$a ~/stuff
Added ~/stuff to dir stack
✪ [1:~/stuff][2:/var/log][3:/tmp]
$g 1
Changed dir to ~/stuff
✪ [1:~/stuff][2:/var/log][3:/tmp]
$pwd
~/stuff
✪ [1:~/stuff][2:/var/log][3:/tmp]
$d 1 3
Deleted ~/stuff from dir stack
Deleted /tmp from dir stack
✪ [1:/var/log]
$pwd
~/stuff
✪ [1:/var/log]
$a "/some/very C4p&4 and/large-.  /" 
Added "/some/very C4p&4 and/large-.  " to dir stack
✪[1:/some/very C4p&4 and/large-.  ][2:/var/log]
$
...

###Can I seek forward/backward a dirStack?

Absolutely!

It includes the bash aliases (gf,gb).

✪ Empty dir stack(a add,d delete,g go number,~num = dir)
mkdir -p /tmp/a/b/c/d
✪ Empty dir stack(a add,d delete,g go number,~num = dir)
a /tmp/a/b/c/d; a /tmp/a/; a /tmp/a/b; a /tmp/a/b/c; 
✪ [1:~][2:/tmp/a][3:/tmp/a/b][4:/tmp/a/b/c][5:/tmp/a/b/c/d/e]
gf a c$
✪ [1:~][2:/tmp/a][3:/tmp/a/b][4:/tmp/a/b/c][5:/tmp/a/b/c/d/e]
gb a 
✪ [1:~][2:/tmp/a][3:/tmp/a/b][4:/tmp/a/b/c][5:/tmp/a/b/c/d/e]
gf d$
...

###Does it work with autocompletion?

Indeed!

✪ [1:/var/log][2:/var][3:/tmp]
$mv  ~3/ (TAB)  /old
yourstuf.log somedir/
...

###Why not $HOME/$OLDPWD?

Cause you can always use (~ or ~-) for that but you can customize it with DIRSTACK_EXCLUDE bash variable.

DIRSTACK_EXCLUDE="/foobar:/tmp"

###How many dirs can it save?

By default 5 but you can customize it.

DIRSTACK_LIMIT=3

###Can I disable it temporarily?

Sure.

DIRSTACK_ENABLED=false

How does it work?

It's a 100% bash script FSM with neat use of the push/popd builtins.

I love FSMs (Finite State Machine)!. :)

TODO

  • del with multiple arguments
  • Screenshots and tutorial
  • Seek forward and backward in your current dir
  • Add bookmarks (am/gm?)
  • Unit testing? (bats)