Skip to content

Instantly share code, notes, and snippets.

@nocd5
Last active April 6, 2017 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocd5/35036cffec1bd22d07cca561a8002809 to your computer and use it in GitHub Desktop.
Save nocd5/35036cffec1bd22d07cca561a8002809 to your computer and use it in GitHub Desktop.
chdir with cho
#!/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