Last active
April 6, 2017 04:05
-
-
Save nocd5/35036cffec1bd22d07cca561a8002809 to your computer and use it in GitHub Desktop.
chdir with cho
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/csh | |
if ("$1" == "") then | |
pushd ~ | |
else if ("$1" =~ */ | "$1" == "..") then | |
pushd $1 | |
else | |
set pattern = `basename $1` | |
set parent = `dirname $1` | |
set dirs = () | |
foreach p (`find "${parent}" -maxdepth 1 -type d -iname "${pattern}*" -o \ | |
-type l -iname "${pattern}*"`) | |
if (${p} != "." & (-d ${p} | -d `readlink ${p}`)) then | |
set dirs = (${dirs} ${p}) | |
endif | |
end | |
if (${#dirs} == 0) then | |
echo "${pattern}: No such file or directory." > /dev/stderr | |
else if (${#dirs} == 1) then | |
pushd ${dirs} | |
else | |
set cands = () | |
foreach d (${dirs}) | |
set cands = ${cands}"\n"`echo ${d} | sed "s/^.\///"`"/" | |
end | |
set target = `echo ${cands} | cho -lb yellow -br` | |
if (${#target} != 0) then | |
pushd ${target} | |
endif | |
endif | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment