這裏有一個簡單的別名的方式侵擾程度較低的替代方案:
alias lx='PATH="./bin:$PATH"'
然後,您可以使用lx
(大號 OCALËX ecution)任何文件夾中,有一個bin
子目錄執行腳本沒有路徑;例如,從當前目錄執行腳本./bin/start-server
,運行:
lx start-server
如果要啓用基於對本地可執行製表完成,以下內容添加到您的bash配置文件(測試在OSX和Linux上):
# Install the custom tab-completion function defined below.
complete -F _complete_lx -- lx
# Command-completion function for lx: tab-completes the executables in
# the ./bin subfolder.
_complete_lx() {
# Set the directory in which to look for local executables.
local localExeDir='./bin'
# Get the current command-line token.
local token=${COMP_WORDS[$COMP_CWORD]}
local tokenLen=${#token}
# Find all local executables.
read -d ' ' -ra localExes < <(find "$localExeDir" -maxdepth 1 -type f -perm -a=x -exec basename -a {} +;)
# Filter the list of local executables
# based on the current command-line token.
# Turn case-insensitive matching temporarily on, if necessary.
local nocasematchWasOff=0
shopt nocasematch >/dev/null || nocasematchWasOff=1
((nocasematchWasOff)) && shopt -s nocasematch
COMPREPLY=()
for localExe in "${localExes[@]}"; do
if [[ ${localExe:0:$((tokenLen))} == "$token" ]]; then
COMPREPLY+=("$localExe")
fi
done
# Restore state of 'nocasematch' option, if necessary.
((nocasematchWasOff)) && shopt -u nocasematch
}
想讓「.runme」腳本在有人向目錄中執行「cd」時自動運行? – 2011-04-08 11:34:19
是的,這是可能的嗎? – 2011-04-08 11:39:50