搜索
首页运维linux运维深入浅出了解Linux和MacOS终端大小写敏感问题(附代码)

之前的文章《一文讲解ajax实现无刷新上传和下载(代码详解)》中,给大家了解了ajax实现无刷新上传和下载。下面本篇文章给大家了解Linux和MacOS终端大小写敏感问题,伙伴们来看看吧。

深入浅出了解Linux和MacOS终端大小写敏感问题(附代码)

Linux和MacOS终端提示大小写不敏感

打开终端,并cd到用户home目录,输入:

echo "set completion-ignore-case on" >> .inputrc

关闭再重新打开终端即可

如果你只想快速解决上面的问题,直接看第三部分即可。

inputrc 文件介绍

Bash和其它大多数shell使用Readline库作为其输入相关的库。Readline库有一些默认的键盘映射,除此之外,也可以通过修改inputrc文件来定制键盘映射。

inputrc文件时Readline库的启动文件,当使用Readline作为输入库的程序启动时,它会自动读取inputrc配置文件,初始化自定义的键盘映射。

inputrc文件的位置由shell的环境变量INPUTRC控制,如果该变量没有设置,缺省的inputrc文件的路径是~/.inputrc

如果该文件~/.inputrc不存在,就会使用系统级(对所有用户生效)的inputrc文件/etc/inputrc。如果某个用户需要修改系统默认的 inputrc配置,可以改动~/.inputrc,这样会覆盖系统的默认配置。

关于如何编辑inputrc文件的信息,运行info bash,参考bashinfo页的Readline Init File这一节,运行info readline以参考readline自己的info页。

inputrc 配置

inputrc文件中,有两种配置:一种是inputrc变量,一种是键盘映射。 注意,在配置该文件时,注释必须占单独的一行,否则可能会有问题。

inputrc变量配置

变量配置的语法如下:

set variable value

常见的变量和配置如下:

completion-ignore-case
#如果设置为开(on),在自动补全时不区分大小写。该配置默认是关。

show-all-if-ambiguous
#这个配置该变了自动补全函数的默认行为。如果设置为开(on),当自动补全的结果有一个以上时,会直接列出这些结果。如果设置为关(off),就会提示一个beep蜂鸣声,当再按下tab时才会列出自动补全的结果。默认这项配置为关。

bell-style
#Controls what happens when Readline wants to ring the terminal bell. If set to ‘none’, Readline never rings the bell. If set to ‘visible’, Readline uses a visible bell if one is available. If set to ‘audible’ (the default), Readline attempts to ring the terminal's bell.

bind-tty-special-chars
#If set to ‘on’, Readline attempts to bind the control characters treated specially by the kernel's terminal driver to their Readline equivalents.

comment-begin
#The string to insert at the beginning of the line when the insert-comment command is executed. The default value is "#".
completion-prefix-display-length

#When set to a value greater than zero, common prefixes longer than this value are replaced with an ellipsis when displaying possible completions.
#e.g. set completion-prefix-display-length 4

completion-query-items
#The number of possible completions that determines when the user is asked whether the list of possibilities should be displayed. If the number of possible completions is greater than this value, Readline will ask the user whether or not he wishes to view them; otherwise, they are simply listed. This variable must be set to an integer value greater than or equal to 0. A negative value means Readline should never ask. The default limit is 100.

convert-meta
#If set to ‘on’, Readline will convert characters with the eighth bit set to an ascii key sequence by stripping the eighth bit and prefixing an <ESC> character, converting them to a meta-prefixed key sequence. The default value is ‘on’.

disable-completion
#If set to ‘On’, Readline will inhibit word completion. Completion characters will be inserted into the line as if they had been mapped to self-insert. The default is ‘off’.

editing-mode
#The editing-mode variable controls which default set of key bindings is used. By default, Readline starts up in Emacs editing mode, where the keystrokes are most similar to Emacs. This variable can be set to either ‘emacs’ or ‘vi’.

echo-control-characters
#When set to ‘on’, on operating systems that indicate they support it, readline echoes a character corresponding to a signal generated from the keyboard. The default is ‘on’.

enable-keypad
#When set to ‘on’, Readline will try to enable the application keypad when it is called. Some systems need this to enable the arrow keys. The default is ‘off’.

enable-meta-key
#When set to ‘on’, Readline will try to enable any meta modifier key the terminal claims to support when it is called. On many terminals, the meta key is used to send eight-bit characters. The default is ‘on’.

expand-tilde
#If set to ‘on’, tilde expansion is performed when Readline attempts word completion. The default is ‘off’.

history-preserve-point
#If set to ‘on’, the history code attempts to place the point (the current cursor position) at the same location on each history line retrieved with previous-history or next-history. The default is ‘off’.

history-size
#Set the maximum number of history entries saved in the history list. If set to zero, the number of entries in the history list is not limited.

horizontal-scroll-mode
#This variable can be set to either ‘on’ or ‘off’. Setting it to ‘on’ means that the text of the lines being edited will scroll horizontally on a single screen line when they are longer than the width of the screen, instead of wrapping onto a new screen line. By default, this variable is set to ‘off’.

input-meta
#If set to ‘on’, Readline will enable eight-bit input (it will not clear the eighth bit in the characters it reads), regardless of what the terminal claims it can support. The default value is ‘off’. The name meta-flag is a synonym for this variable.

isearch-terminators
#The string of characters that should terminate an incremental search without subsequently executing the character as a command. If this variable has not been given a value, the characters <ESC> and C-J will terminate an incremental search.

keymap
#Sets Readline&#39;s idea of the current keymap for key binding commands. Acceptable keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is equivalent to emacs-standard. The default value is emacs. The value of the editing-mode variable also affects the default keymap.

mark-directories
#If set to ‘on’, completed directory names have a slash appended. The default is ‘on’.

mark-modified-lines
#This variable, when set to ‘on’, causes Readline to display an asterisk (*) at the start of history lines which have been modified. This variable is ‘off’ by default.

mark-symlinked-directories
#If set to ‘on’, completed names which are symbolic links to directories have a slash appended (subject to the value of mark-directories). The default is ‘off’.

match-hidden-files
#This variable, when set to ‘on’, causes Readline to match files whose names begin with a ‘.’ (hidden files) when performing filename completion, unless the leading ‘.’ is supplied by the user in the filename to be completed. This variable is ‘on’ by default.

output-meta
#If set to ‘on’, Readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence. The default is ‘off’.

page-completions
#If set to ‘on’, Readline uses an internal more-like pager to display a screenful of possible completions at a time. This variable is ‘on’ by default.

print-completions-horizontally
#If set to ‘on’, Readline will display completions with matches sorted horizontally in alphabetical order, rather than down the screen. The default is ‘off’.

revert-all-at-newline
If set to ‘on’, Readline will undo all changes to history lines before returning when accept-line is executed. By default, history lines can be modified and retain individual undo lists across calls to readline. The default is ‘off’.

show-all-if-unmodified
#This alters the default behavior of the completion functions in a fashion similar to show-all-if-ambiguous. If set to ‘on’, words which have more than one possible completion without any possible partial completion (the possible completions don&#39;t share a common prefix) cause the matches to be listed immediately instead of ringing the bell. The default value is ‘off’.

skip-completed-text
#If set to ‘on’, this alters the default completion behavior when inserting a single match into the line. It&#39;s only active when performing completion in the middle of a word. If enabled, readline does not insert characters from the completion that match characters after point in the word being completed, so portions of the word following the cursor are not duplicated. For instance, if this is enabled, attempting completion when the cursor is after the ‘e’ in ‘Makefile’ will result in ‘Makefile’ rather than ‘Makefilefile’, assuming there is a single possible completion. The default value is ‘off’.

visible-stats
#If set to ‘on’, a character denoting a file&#39;s type is appended to the filename when listing possible completions. The default is ‘off’.

键盘映射配置

配置inputrc变量的语法如下:

keyname: function-name or macro

#keyname必须是英文,可以是Control-u、Control-k等。并且keyname和冒号之间不能有空格,如果有空格会被认为是keyname的一部分。keyname的写法多样,取决于自己的喜好。
#下面是一些键盘映射配置的例子:

Control-u: universal-argument C-u is bound to the function universal-argument

Meta-Rubout: backward-kill-word M-DEL is bound to the function backward-kill-word

Control-o: "> output" C-o is bound to run the macro expressed on the right hand side (that is, to insert the text ‘> output’ into the line)

Control-j: menu-complete C-j is bound to cycle through the available tab completions.

Control-k: menu-complete-backward C-k is bound to cycle backwards through the available tab completions.

"\t": menu-complete Use tab to cycle through all the possible completions.

"\C-p": history-search-backward Map control-p to allow search for completions to the current line from your history. e.g. type “git” and then hit control-p to cycle through all the recent git commands.

"\ep": history-search-backward Map escape-p to allow search for completions to the current line from your history. e.g. type “git” and then hit escape-p to cycle through all the recent git commands.

"\e[A": history-search-backward Map Up arrow to allow search for completions to the current line from your history. e.g. type “git” and then hit UP to cycle through all the recent git commands.

"\e[B": history-search-forward Map Down arrow to allow search for completions to the current line from your history. e.g. type “git” and then hit DOWN to cycle back through all the recent git commands.

"\C-d": kill-whole-line Map control-d to kill the whole line.

设置MacOS下自动补全不区分大小写

通过上面的介绍,解决这个问题应该是绰绰有余了。打开用户主目录下的文件~/.inputrc(如果没有的话,就新建该文件),在其中添加如下配置:

# 设置自动补全不区分大小写
set completion-ignore-case on
# 当有一个以上自动补全结果时,直接列出,不用beep提示
set show-all-if-ambiguous on

保存该文件,然后,重启命令行,就会发现自动补全不区分大小写已经生效了。 网上好多结果中,还需要多加一个下面的配置:

TAB: menu-complete

这个配置的目的是,在列出自动补全的结果之后,再按一次tab键,就会自动在自动补全列表中选择,而不是一直展示自动补全列表。

推荐学习:Mac OS入门教程Linux视频教程

以上是深入浅出了解Linux和MacOS终端大小写敏感问题(附代码)的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:禅境花园。如有侵权,请联系admin@php.cn删除
什么是linux设备节点什么是linux设备节点Apr 18, 2022 pm 08:10 PM

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

Linux中open和fopen的区别有哪些Linux中open和fopen的区别有哪些Apr 29, 2022 pm 06:57 PM

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

linux中什么叫端口映射linux中什么叫端口映射May 09, 2022 pm 01:49 PM

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

linux中eof是什么linux中eof是什么May 07, 2022 pm 04:26 PM

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

什么是linux交叉编译什么是linux交叉编译Apr 29, 2022 pm 06:47 PM

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

linux怎么判断pcre是否安装linux怎么判断pcre是否安装May 09, 2022 pm 04:14 PM

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux怎么查询mac地址linux怎么查询mac地址Apr 24, 2022 pm 08:01 PM

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

linux中rpc是什么意思linux中rpc是什么意思May 07, 2022 pm 04:48 PM

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
1 个月前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境