-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcd_func
More file actions
57 lines (57 loc) · 1.4 KB
/
cd_func
File metadata and controls
57 lines (57 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# From http://aijazansari.com/2010/02/20/navigating-the-directory-stack-in-bash/index.html
# An enhanced 'cd' - push directories
# onto a stack as you navigate to it.
#
# The current directory is at the top
# of the stack.
#
function stack_cd {
if [ $1 ]; then
# use the pushd bash command to push the directory
# to the top of the stack, and enter that directory
pushd "$1" > /dev/null
else
# the normal cd behavior is to enter $HOME if no
# arguments are specified
pushd $HOME > /dev/null
fi
}
# the cd command is now an alias to the stack_cd function
#
alias cd=stack_cd
# Swap the top two directories on the stack
#
function swap {
pushd > /dev/null
}
# s is an alias to the swap function
alias s=swap
# Pop the top (current) directory off the stack
# and move to the next directory
#
function pop_stack {
popd > /dev/null
}
alias p=pop_stack
# Display the stack of directories and prompt
# the user for an entry.
#
# If the user enters 'p', pop the stack.
# If the user enters a number, move that
# directory to the top of the stack
# If the user enters 'q', don't do anything.
#
function display_stack
{
dirs -v
echo -n "#: "
read dir
if [[ $dir = 'p' ]]; then
pushd > /dev/null
elif [[ $dir != 'q' ]]; then
d=$(dirs -l +$dir);
popd +$dir > /dev/null
pushd "$d" > /dev/null
fi
}
alias d=display_stack