mirror of https://github.com/nirenjan/dotfiles.git
Reformat smartwd indentation to compy with Ruby coding guidelines
parent
c8654cc971
commit
38a6c23cc8
|
@ -14,56 +14,56 @@ DIR_R = 2
|
||||||
PWDLEN = 14
|
PWDLEN = 14
|
||||||
|
|
||||||
def backslash_w
|
def backslash_w
|
||||||
homedir = ENV['HOME']
|
homedir = ENV['HOME']
|
||||||
pwd = ENV['PWD']
|
pwd = ENV['PWD']
|
||||||
print pwd.gsub(homedir, '~')
|
print pwd.gsub(homedir, '~')
|
||||||
end
|
end
|
||||||
|
|
||||||
def smartwd
|
def smartwd
|
||||||
username = ENV['USER']
|
username = ENV['USER']
|
||||||
homedir = ENV['HOME']
|
homedir = ENV['HOME']
|
||||||
pwd = ENV['PWD']
|
pwd = ENV['PWD']
|
||||||
|
|
||||||
path = pwd.split('/')
|
path = pwd.split('/')
|
||||||
|
|
||||||
# Ignore the root path
|
# Ignore the root path
|
||||||
if (path.length > 0)
|
if (path.length > 0)
|
||||||
index = path.index(username)
|
index = path.index(username)
|
||||||
if index
|
if index
|
||||||
prefix = path.shift(index + 1)
|
prefix = path.shift(index + 1)
|
||||||
|
|
||||||
# We need to map additional paths in environments where the user
|
|
||||||
# may have more than one available folder in his/her name.
|
|
||||||
if prefix.join('/') == homedir
|
|
||||||
path.unshift('~')
|
|
||||||
else
|
|
||||||
# The first entry in the prefix array is the empty string
|
|
||||||
pre = prefix[1].split('').shift(4).join('') + '~'
|
|
||||||
path.unshift(pre)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# Replace the first two entries in the array with /<entry1>
|
|
||||||
# (because the first entry is always empty string)
|
|
||||||
prefix = path.shift(2).join('/')
|
|
||||||
path.unshift(prefix)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check to make sure that both the DIRLIM and PWDLEN constraints
|
# We need to map additional paths in environments where the user
|
||||||
# are met before splitting
|
# may have more than one available folder in his/her name.
|
||||||
pwd = path.join('/')
|
if prefix.join('/') == homedir
|
||||||
if path.length > DIRLIM and pwd.length > PWDLEN
|
path.unshift('~')
|
||||||
pwd_l = path.shift(DIR_L).join('/')
|
else
|
||||||
pwd_r = path.pop(DIR_R).join('/')
|
# The first entry in the prefix array is the empty string
|
||||||
pwd = pwd_l + '/.../' + pwd_r
|
pre = prefix[1].split('').shift(4).join('') + '~'
|
||||||
end
|
path.unshift(pre)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# Replace the first two entries in the array with /<entry1>
|
||||||
|
# (because the first entry is always empty string)
|
||||||
|
prefix = path.shift(2).join('/')
|
||||||
|
path.unshift(prefix)
|
||||||
end
|
end
|
||||||
|
|
||||||
print pwd
|
# Check to make sure that both the DIRLIM and PWDLEN constraints
|
||||||
|
# are met before splitting
|
||||||
|
pwd = path.join('/')
|
||||||
|
if path.length > DIRLIM and pwd.length > PWDLEN
|
||||||
|
pwd_l = path.shift(DIR_L).join('/')
|
||||||
|
pwd_r = path.pop(DIR_R).join('/')
|
||||||
|
pwd = pwd_l + '/.../' + pwd_r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print pwd
|
||||||
end
|
end
|
||||||
|
|
||||||
if (ruby_release < min_release)
|
if (ruby_release < min_release)
|
||||||
backslash_w
|
backslash_w
|
||||||
else
|
else
|
||||||
smartwd
|
smartwd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue