?? cdll
字號:
############################################################################## cdll# by Phil Braham## ############################################# Latest version of this script available from# http://freshmeat.net/projects/cd/# ############################################## .cd_new## An enhancement of the Unix cd command## There are unlimited stack entries and special entries. The stack# entries keep the last cd_maxhistory# directories that have been used. The special entries can be assigned# to commonly used directories.## The special entries may be pre-assigned by setting the environment# variables CDSn or by using the -u or -U command.## The following is a suggestion for the .profile file:## . cdll # Set up the cd command# alias cd='cd_new' # Replace te cd command# cd -U # Upload pre-assigned entries for# #+ the stact and special entries# cd -D # Set non-default mode# alias @="cd_new @" # Allow @ to be used to get history## For help type:## cd -h or# cd -H################################################################################ Version 1.2.1## Written by Phil Braham - Realtime Software Pty Ltd# (realtime@mpx.com.au)# Please send any suggestions or enhancements to the author (also at# phil@braham.net)#############################################################################cd_hm (){ ${PRINTF} "%s" "cd [dir] [0-9] [@[s|h] [-g [<dir>]] [-d] [-D] [-r<n>] [dir|0-9] [-R<n>] [<dir>|0-9] [-s<n>] [-S<n>] [-u] [-U] [-f] [-F] [-h] [-H] [-v] <dir> Go to directory 0-n Goto previous directory (0 is previous, 1 is last but 1 etc) n is up to max history (default is 50) @ List history and special entries @h List history entries @s List special entries -g [<dir>] Go to literal name (bypass special names) This is to allow access to dirs called '0','1','-h' etc -d Change default action - verbose. (See note) -D Change default action - silent. (See note) -s<n> Go to the special entry <n>* -S<n> Go to the special entry <n> and replace it with the current dir* -r<n> [<dir>] Go to directory <dir> and then put it on special entry <n>* -R<n> [<dir>] Go to directory <dir> and put current dir on special entry <n>* -a<n> Alternative suggested directory. See note below. -f [<file>] File entries to <file>. -u [<file>] Update entries from <file>. If no filename supplied then default file (${CDPath}${2:-"$CDFile"}) is used -F and -U are silent versions -v Print version number -h Help -H Detailed help *The special entries (0 - 9) are held until log off, replaced by another entry or updated with the -u command Alternative suggested directories: If a directory is not found then CD will suggest any possibilities. These are directories starting with the same letters and if any are found they are listed prefixed with -a<n> where <n> is a number. It's possible to go to the directory by entering cd -a<n> on the command line. The directory for -r<n> or -R<n> may be a number. For example: $ cd -r3 4 Go to history entry 4 and put it on special entry 3 $ cd -R3 4 Put current dir on the special entry 3 and go to history entry 4 $ cd -s3 Go to special entry 3 Note that commands R,r,S and s may be used without a number and refer to 0: $ cd -s Go to special entry 0 $ cd -S Go to special entry 0 and make special entry 0 current dir $ cd -r 1 Go to history entry 1 and put it on special entry 0 $ cd -r Go to history entry 0 and put it on special entry 0 " if ${TEST} "$CD_MODE" = "PREV" then ${PRINTF} "$cd_mnset" else ${PRINTF} "$cd_mset" fi}cd_Hm (){ cd_hm ${PRINTF} "%s" " The previous directories (0-$cd_maxhistory) are stored in the environment variables CD[0] - CD[$cd_maxhistory] Similarly the special directories S0 - $cd_maxspecial are in the environment variable CDS[0] - CDS[$cd_maxspecial] and may be accessed from the command line The default pathname for the -f and -u commands is $CDPath The default filename for the -f and -u commands is $CDFile Set the following environment variables: CDL_PROMPTLEN - Set to the length of prompt you require. Prompt string is set to the right characters of the current directory. If not set then prompt is left unchanged CDL_PROMPT_PRE - Set to the string to prefix the prompt. Default is: non-root: \"\\[\\e[01;34m\\]\" (sets colour to blue). root: \"\\[\\e[01;31m\\]\" (sets colour to red). CDL_PROMPT_POST - Set to the string to suffix the prompt. Default is: non-root: \"\\[\\e[00m\\]$\" (resets colour and displays $). root: \"\\[\\e[00m\\]#\" (resets colour and displays #). CDPath - Set the default path for the -f & -u options. Default is home directory CDFile - Set the default filename for the -f & -u options. Default is cdfile " cd_version}cd_version (){ printf "Version: ${VERSION_MAJOR}.${VERSION_MINOR} Date: ${VERSION_DATE}\n"}## Truncate right.## params:# p1 - string# p2 - length to truncate to## returns string in tcd#cd_right_trunc (){ local tlen=${2} local plen=${#1} local str="${1}" local diff local filler="<--" if ${TEST} ${plen} -le ${tlen} then tcd="${str}" else let diff=${plen}-${tlen} elen=3 if ${TEST} ${diff} -le 2 then let elen=${diff} fi tlen=-${tlen} let tlen=${tlen}+${elen} tcd=${filler:0:elen}${str:tlen} fi}## Three versions of do history:# cd_dohistory - packs history and specials side by side# cd_dohistoryH - Shows only hstory# cd_dohistoryS - Shows only specials#cd_dohistory (){ cd_getrc ${PRINTF} "History:\n" local -i count=${cd_histcount} while ${TEST} ${count} -ge 0 do cd_right_trunc "${CD[count]}" ${cd_lchar} ${PRINTF} "%2d %-${cd_lchar}.${cd_lchar}s " ${count} "${tcd}" cd_right_trunc "${CDS[count]}" ${cd_rchar} ${PRINTF} "S%d %-${cd_rchar}.${cd_rchar}s\n" ${count} "${tcd}" count=${count}-1 done}cd_dohistoryH (){ cd_getrc ${PRINTF} "History:\n" local -i count=${cd_maxhistory} while ${TEST} ${count} -ge 0 do ${PRINTF} "${count} %-${cd_flchar}.${cd_flchar}s\n" ${CD[$count]} count=${count}-1 done}cd_dohistoryS (){ cd_getrc ${PRINTF} "Specials:\n" local -i count=${cd_maxspecial} while ${TEST} ${count} -ge 0 do ${PRINTF} "S${count} %-${cd_flchar}.${cd_flchar}s\n" ${CDS[$count]} count=${count}-1 done}cd_getrc (){ cd_flchar=$(stty -a | awk -F \; '/rows/ { print $2 $3 }' | awk -F \ '{ print $4 }') if ${TEST} ${cd_flchar} -ne 0 then cd_lchar=${cd_flchar}/2-5 cd_rchar=${cd_flchar}/2-5 cd_flchar=${cd_flchar}-5 else cd_flchar=${FLCHAR:=75} # cd_flchar is used for for the @s & @h history cd_lchar=${LCHAR:=35} cd_rchar=${RCHAR:=35} fi}cd_doselection (){ local -i nm=0 cd_doflag="TRUE" if ${TEST} "${CD_MODE}" = "PREV" then if ${TEST} -z "$cd_npwd" then cd_npwd=0 fi fi tm=$(echo "${cd_npwd}" | cut -b 1) if ${TEST} "${tm}" = "-" then pm=$(echo "${cd_npwd}" | cut -b 2) nm=$(echo "${cd_npwd}" | cut -d $pm -f2) case "${pm}" in a) cd_npwd=${cd_sugg[$nm]} ;; s) cd_npwd="${CDS[$nm]}" ;; S) cd_npwd="${CDS[$nm]}" ; CDS[$nm]=`pwd` ;; r) cd_npwd="$2" ; cd_specDir=$nm ; cd_doselection "$1" "$2";; R) cd_npwd="$2" ; CDS[$nm]=`pwd` ; cd_doselection "$1" "$2";; esac fi if ${TEST} "${cd_npwd}" != "." -a "${cd_npwd}" != ".." -a "${cd_npwd}" -le ${cd_maxhistory} >>/dev/null 2>&1 then cd_npwd=${CD[$cd_npwd]} else case "$cd_npwd" in @) cd_dohistory ; cd_doflag="FALSE" ;; @h) cd_dohistoryH ; cd_doflag="FALSE" ;; @s) cd_dohistoryS ; cd_doflag="FALSE" ;; -h) cd_hm ; cd_doflag="FALSE" ;; -H) cd_Hm ; cd_doflag="FALSE" ;; -f) cd_fsave "SHOW" $2 ; cd_doflag="FALSE" ;; -u) cd_upload "SHOW" $2 ; cd_doflag="FALSE" ;; -F) cd_fsave "NOSHOW" $2 ; cd_doflag="FALSE" ;; -U) cd_upload "NOSHOW" $2 ; cd_doflag="FALSE" ;; -g) cd_npwd="$2" ;; -d) cd_chdefm 1; cd_doflag="FALSE" ;; -D) cd_chdefm 0; cd_doflag="FALSE" ;; -r) cd_npwd="$2" ; cd_specDir=0 ; cd_doselection "$1" "$2";; -R) cd_npwd="$2" ; CDS[0]=`pwd` ; cd_doselection "$1" "$2";; -s) cd_npwd="${CDS[0]}" ;; -S) cd_npwd="${CDS[0]}" ; CDS[0]=`pwd` ;; -v) cd_version ; cd_doflag="FALSE";; esac fi}cd_chdefm (){ if ${TEST} "${CD_MODE}" = "PREV" then CD_MODE="" if ${TEST} $1 -eq 1 then ${PRINTF} "${cd_mset}" fi else CD_MODE="PREV" if ${TEST} $1 -eq 1 then ${PRINTF} "${cd_mnset}" fi fi}cd_fsave (){ local sfile=${CDPath}${2:-"$CDFile"} if ${TEST} "$1" = "SHOW" then ${PRINTF} "Saved to %s\n" $sfile fi ${RM} -f ${sfile} local -i count=0 while ${TEST} ${count} -le ${cd_maxhistory} do echo "CD[$count]=\"${CD[$count]}\"" >> ${sfile} count=${count}+1 done count=0 while ${TEST} ${count} -le ${cd_maxspecial} do echo "CDS[$count]=\"${CDS[$count]}\"" >> ${sfile} count=${count}+1 done}cd_upload (){ local sfile=${CDPath}${2:-"$CDFile"} if ${TEST} "${1}" = "SHOW" then ${PRINTF} "Loading from %s\n" ${sfile} fi . ${sfile}}cd_new (){ local -i count local -i choose=0 cd_npwd="${1}" cd_specDir=-1 cd_doselection "${1}" "${2}" if ${TEST} ${cd_doflag} = "TRUE" then if ${TEST} "${CD[0]}" != "`pwd`" then count=$cd_maxhistory while ${TEST} $count -gt 0 do CD[$count]=${CD[$count-1]} count=${count}-1 done CD[0]=`pwd` fi command cd "${cd_npwd}" 2>/dev/null if ${TEST} $? -eq 1 then
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -