mirror of https://github.com/nirenjan/dotfiles.git
Fix smartwd script to ensure that it always works
With Ruby version 1.8.5, the smartwd script would abort with an error that the shift method would take no arguments. Therefore, I have restricted the use of the script to ruby version 1.8.7 and above. On older versions, it will simply behave the same as \w in PS1 of bash.master
parent
c64326cd06
commit
f962d96980
14
smartwd
14
smartwd
|
@ -3,12 +3,22 @@
|
||||||
# Script to smartly chop off portions of the current working directory for
|
# Script to smartly chop off portions of the current working directory for
|
||||||
# use in the shell prompt
|
# use in the shell prompt
|
||||||
|
|
||||||
|
# Some of the methods don't work with Ruby versions older than 1.8.7
|
||||||
|
min_release = "1.8.7 (2008-08-11)"
|
||||||
|
ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
|
||||||
|
|
||||||
# Constants used to decide when to start chopping
|
# Constants used to decide when to start chopping
|
||||||
DIRLIM = 5
|
DIRLIM = 5
|
||||||
DIR_L = 3
|
DIR_L = 3
|
||||||
DIR_R = 2
|
DIR_R = 2
|
||||||
PWDLEN = 14
|
PWDLEN = 14
|
||||||
|
|
||||||
|
def backslash_w
|
||||||
|
homedir = ENV['HOME']
|
||||||
|
pwd = ENV['PWD']
|
||||||
|
print pwd.gsub(homedir, '~')
|
||||||
|
end
|
||||||
|
|
||||||
def smartwd
|
def smartwd
|
||||||
username = ENV['USER']
|
username = ENV['USER']
|
||||||
homedir = ENV['HOME']
|
homedir = ENV['HOME']
|
||||||
|
@ -51,5 +61,9 @@ def smartwd
|
||||||
print pwd
|
print pwd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (ruby_release < min_release)
|
||||||
|
backslash_w
|
||||||
|
else
|
||||||
smartwd
|
smartwd
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue