Skip to content

Instantly share code, notes, and snippets.

@Ishotihadus
Created April 20, 2015 11:28
Show Gist options
  • Save Ishotihadus/aac4baf5d053be2cd027 to your computer and use it in GitHub Desktop.
Save Ishotihadus/aac4baf5d053be2cd027 to your computer and use it in GitHub Desktop.
bashで動かせるすごいcd。ディレクトリ名を打ち込まなくてもカレントディレクトリを移動できる。source supercd.shで動かす。
#!/bin/bash
shopt -s dotglob
while :
do
endflg=0
printf "\033[1;31m"
echo `pwd`
printf "\033[0;39m"
declare -a array=()
for dir in */
do
array=("${array[@]}" "$dir")
done
echo "-1: ../"
for ((i=0; i<${#array[*]}; i++)); do
echo "$i: ${array[i]}"
done
recdir=""
while :
do
printf "> "
read ans
if [ -z "$ans" ]
then
cd
break
elif [ ${ans} = "q" ]
then
endflg=1
break
elif [ ${ans} = "ls" ]
then
ls -F | grep -v /
elif [ ${ans} = "mcd" ]
then
printf "new dirname> "
read dirname
if [ -n "$dirname" ]
then
mkdir "$dirname"
cd "$dirname"
break
fi
elif [ "$ans" -ge 0 -a "$ans" -lt ${#array[*]} ]
then
recdir=${array[ans]}
echo "$recdir"
cd "$recdir"
break
elif [ "$ans" -eq -1 ]
then
cd "../"
break
else
echo "?"
fi
done
if [ $endflg -eq 1 ]
then
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment