সজোরে আঘাত
set completion-ignore-case onইন ~/.inputrc(বা bind 'set completion-ignore-case on'মধ্যে ~/.bashrc) আমার প্রস্তাবনা হবে। আপনি যদি পুরো নামটি টাইপ করতে চলেছেন তবে Shiftকীটির কয়েকটি টিপে টিপছেন কেন ?
তবে আপনি যদি সত্যিই এটি চান তবে এখানে একটি মোড়কের চারপাশে cdএকটি সঠিক মিলের চেষ্টা করে, এবং যদি কিছুই না থাকে তবে কেস-সংবেদনশীল ম্যাচটি সন্ধান করে এবং যদি এটি অনন্য হয় তবে তা সম্পাদন করে। এটি nocaseglobকেস-সংবেদনশীল গ্লোববিংয়ের জন্য শেল বিকল্পটি ব্যবহার করে এবং যুক্তি যুক্ত করে একটি গ্লোবে পরিণত করে @()(যা কোনও কিছুর সাথে মেলে না এবং প্রয়োজন extglob)। extglobবিকল্প অন্যথায় ব্যাশ এমনকি এটি বিশ্লেষণ করতে পারি না, যখন ফাংশন সংজ্ঞায়িত চালু করতে হবে। এই ফাংশনটি সমর্থন করে না CDPATH।
shopt -s extglob
cd () {
builtin cd "$@" 2>/dev/null && return
local options_to_unset=; local -a matches
[[ :$BASHOPTS: = *:extglob:* ]] || options_to_unset="$options_to_unset extglob"
[[ :$BASHOPTS: = *:nocaseglob:* ]] || options_to_unset="$options_to_unset nocaseglob"
[[ :$BASHOPTS: = *:nullglob:* ]] || options_to_unset="$options_to_unset nullglob"
shopt -s extglob nocaseglob nullglob
matches=("${!#}"@()/)
shopt -u $options_to_unset
case ${#matches[@]} in
0) # There is no match, even case-insensitively. Let cd display the error message.
builtin cd "$@";;
1)
matches=("$@" "${matches[0]}")
unset "matches[$(($#-1))]"
builtin cd "${matches[@]}";;
*)
echo "Ambiguous case-insensitive directory match:" >&2
printf "%s\n" "${matches[@]}" >&2
return 3;;
esac
}
ksh
আমি যখন তা করছি, এখানে ksh93 এর জন্য একই ধরণের ফাংশন। ~(i)কেস-অবশ মিলের জন্য পরিবর্তিত সঙ্গে বেমানান হবে বলে মনে হয় /প্রত্যয় শুধুমাত্র ডিরেক্টরি মেলে (এই ksh আমার রিলিজে বাগ হতে পারে)। তাই আমি নন-ডিরেক্টরিগুলি ছাটাই করার জন্য একটি ভিন্ন কৌশল ব্যবহার করি।
cd () {
command cd "$@" 2>/dev/null && return
typeset -a args; typeset previous target; typeset -i count=0
args=("$@")
for target in ~(Ni)"${args[$(($#-1))]}"; do
[[ -d $target ]] || continue
if ((count==1)); then printf "Ambiguous case-insensitive directory match:\n%s\n" "$previous" >&2; fi
if ((count)); then echo "$target"; fi
((++count))
previous=$target
done
((count <= 1)) || return 3
args[$(($#-1))]=$target
command cd "${args[@]}"
}
Zsh
অবশেষে, এখানে একটি zsh সংস্করণ। আবার কেস-সংবেদনশীল সমাপ্তির অনুমতি দেওয়া সম্ভবত সেরা বিকল্প। নীচের সেটিংটি যদি কেস-সংবেদনশীল গ্লোব্বিংয়ে ফিরে আসে তবে কোনও সঠিক-কেস ম্যাচ না হলে:
zstyle ':completion:*' '' matcher-list 'm:{a-z}={A-Z}'
''যথাযথ ক্ষেত্রে মিল থাকলেও সমস্ত কেস-সংবেদনশীল ম্যাচগুলি দেখানোর জন্য সরান । আপনি এটির মেনু ইন্টারফেস থেকে সেট করতে পারেন compinstall।
cd () {
builtin cd "$@" 2>/dev/null && return
emulate -L zsh
setopt local_options extended_glob
local matches
matches=( (#i)${(P)#}(N/) )
case $#matches in
0) # There is no match, even case-insensitively. Try cdpath.
if ((#cdpath)) &&
[[ ${(P)#} != (|.|..)/* ]] &&
matches=( $^cdpath/(#i)${(P)#}(N/) ) &&
((#matches==1))
then
builtin cd $@[1,-2] $matches[1]
return
fi
# Still nothing. Let cd display the error message.
builtin cd "$@";;
1)
builtin cd $@[1,-2] $matches[1];;
*)
print -lr -- "Ambiguous case-insensitive directory match:" $matches >&2
return 3;;
esac
}
backUPএবংbackUp, কিভাবে হবেbackupকোন কোন ডাইরেক্টরি আপনার যেতে চাও?