-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkcd.sh
28 lines (27 loc) · 830 Bytes
/
kcd.sh
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
#!/bin/bash
######################################################################
# Author: [email protected]
# Date: Sat Jan 25 17:57:55 2014
# File: kcd.sh
#
# Usage: kcd old new
# Description: kcd takes the pathname of `PWD' and tries to replace
# string `old' with `new'. If succeeds, `cd' to the resulting directory
######################################################################
function kcd()
{
local newdir=""
case "$#" in
0 | 1 ) builtin cd $1 ;;
2 )
if echo "${PWD}" | grep "$1" > /dev/null; then
newdir="${PWD//$1/$2}"
builtin cd "${newdir}"
else
echo "bash: cd: bad substitution" >&2
return 1
fi ;;
* ) echo "bash: cd: wrong arg count" 1>&2
return 1 ;;
esac
}