[英]Autofill is failing after creating a “local” alias in my ~/.bashrc file
我在.bashrc文件中添加了别名。 我这样做并运行源〜/ .bashrc之后,自动填充开始在Ubuntu命令提示符下引发错误。 该错误将我定向到bash_completion文件的第295行,以查找错误的语法。
当我打开该文件并转到第295行时,看不到任何错误的语法。 这是我要添加的代码行以及我收到的错误。
我最初添加到.bashrc
文件中的别名:
alias local='cd /mnt/c/Users/NYCZE/OneDrive/'
当我运行source ~/.bashrc
来实现此别名时抛出错误:
bash: /usr/share/bash-completion/bash_completion: line 295: syntax error near unexpected token `('
bash: /usr/share/bash-completion/bash_completion: line 295: `('
在我的bash_completion
文件中包含第295行的函数:
__reassemble_comp_words_by_ref()
{
local exclude i j line ref # This line right here is the problem one
# Exclude word separator characters?
if [[ $1 ]]; then
# Yes, exclude word separator characters;
# Exclude only those characters, which were really included
exclude="${1//[^$COMP_WORDBREAKS]}"
fi
# Default to cword unchanged
printf -v "$3" %s "$COMP_CWORD"
# Are characters excluded which were former included?
if [[ $exclude ]]; then
# Yes, list of word completion separators has shrunk;
line=$COMP_LINE
# Re-assemble words to complete
for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
# Is current word not word 0 (the command itself) and is word not
# empty and is word made up of just word separator characters to
# be excluded and is current word not preceded by whitespace in
# original line?
while [[ $i -gt 0 && ${COMP_WORDS[$i]} == +([$exclude]) ]]; do
# Is word separator not preceded by whitespace in original line
# and are we not going to append to word 0 (the command
# itself), then append to current word.
[[ $line != [[:blank:]]* ]] && (( j >= 2 )) && ((j--))
# Append word separator to current or new word
ref="$2[$j]"
printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}"
# Indicate new cword
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
# Remove optional whitespace + word separator from line copy
line=${line#*"${COMP_WORDS[$i]}"}
# Start new word if word separator in original line is
# followed by whitespace.
[[ $line == [[:blank:]]* ]] && ((j++))
# Indicate next word if available, else end *both* while and
# for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
done
# Append word to current word
ref="$2[$j]"
printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}"
# Indicate new cword
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
# Remove optional whitespace + word separator from line copy
line=${line#*"${COMP_WORDS[$i]}"}
# Start new word if word separator in original line is
# followed by whitespace.
[[ $line == [[:blank:]]* ]] && ((j++))
# Indicate next word if available, else end *both* while and
# for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
done
# Append word to current word
ref="$2[$j]"
printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}"
# Remove optional whitespace + word from line copy
line=${line#*"${COMP_WORDS[i]}"}
# Indicate new cword
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
done
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
else
# No, list of word completions separators hasn't changed;
for i in ${!COMP_WORDS[@]}; do
printf -v "$2[i]" %s "${COMP_WORDS[i]}"
done
fi
}
local
是一个保留关键字,在许多Bash完成包中广泛使用,并且通常在具有功能的Bash代码中使用。 您真的不想覆盖它,因为那样会破坏那些程序包。 别称您的别名。
(也许也根本不使用别名-Shell函数的用途更加广泛-但这不会改变问题的实质。)
local
是内置的shell。 你可以从这里看到
type local
别名之后,它已变成cd
。 现在,相同type
命令将给出
local is aliased to `cd /mnt/c/Users/NYCZE/OneDrive/'
现在,我的/ usr / share / bash-completion / bash_completion文件中的第295行是
local cword words=()
因此, local
不再具有该文件所期望的行为。 文件中的行类似地使用local
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.