-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcs_function
More file actions
executable file
·43 lines (34 loc) · 921 Bytes
/
cs_function
File metadata and controls
executable file
·43 lines (34 loc) · 921 Bytes
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
#!/bin/bash
# This script defines a function, named 'cs',
# which wraps the original bulti in 'cd' function,
# adding the functionality of storing the current
# PWD location and persist this location across
# another instances of the BASH shell.
# To be effective it needs to be called at each
# bash starting, on possible way to do this is
# to call it in your .bashrc file:
# source ~/scripts/cs_function
# File to store the current PWD location
CS_TMP="$HOME/.tmp_current_dir"
# A 'cd' function wrapper
function cs()
{
# check if the 'cs' function has some arguments
if [ $# -eq 0 ]
then
cd
else
cd "$*"
fi
# Saving the PWD location
echo $PWD > $CS_TMP
}
# Loading the previously stored PWD location and
# defining it as the current one
if [ -f "$CS_TMP" ]
then
cd "`cat $CS_TMP`"
fi
# Replacing the original 'cd' function by its 'cs'
# wrapper:
alias cd="cs"