[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] cd command completion from a numerical number to ../{n}?
From: |
Peng Yu |
Subject: |
[Help-bash] cd command completion from a numerical number to ../{n}? |
Date: |
Fri, 26 Apr 2013 23:46:13 -0500 |
Hi,
When I type 'cd 2'<TAB>, I want to expand it to 'cd ../../' where 2
determines the number of '../'. When it is not a number of cd, I want
the completion be done as the default. I came up with the following
solution. Is it the best one?
_cd_command() {
local i="$2"
if [[ "$i" =~ [0-9]+ ]]
then
unset COMPREPLY
while [ "$i" -ne 0 ]
do
COMPREPLY=../$COMPREPLY
((i=i-1))
done
else
COMPREPLY=("$i"*/)
if [ ! -e "$COMPREPLY" ]
then
unset COMPREPLY
else
COMPREPLY=("address@hidden/}")
fi
fi
}
complete -F _cd_command -o nospace -o filenames cd
Regards,
Peng
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-bash] cd command completion from a numerical number to ../{n}?,
Peng Yu <=