aboutsummaryrefslogtreecommitdiff
path: root/lcd.sh
blob: 1cd19ea046eeef6aed706a6f091f860e1da04c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# lcd.sh - "Linked" cd, for people who use multiple terminals.

# Copy me to e.g. ~/.lcd.sh, then in your .bash_profile, .bashrc,
# or whatever shell startup script you use:

#   [ -e ~/.lcd.sh ] && source ~/.lcd.sh

# Log out & back in, or close and restart all your terminal windows.

# Now when you type a cd command in one shell, such as:
#   cd /usr/src/linux-$( uname -r )/Documentation
# ...you can switch over to another terminal and type:
#   lcd
# ...and now that terminal is cd'ed to the same directory.

cd() {
  builtin cd "$@"
  pwd > ~/.lcd.dir
}  

lcd() {
  [ -e ~/.lcd.dir ] && cd "$( cat ~/.lcd.dir )"
}