本文转载自公众号“读芯术”(ID:AI_Discovery)。
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、做网站、平鲁网络推广、小程序定制开发、平鲁网络营销、平鲁企业策划、平鲁品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供平鲁建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
在十多年的开发生涯中,笔者热衷于使用shell。命令永远不变,笔者可以创建可靠、快捷的自定义快捷方式,但默认值欠佳。阅读本文将带你了解如何在系统上获得很棒的shell +终端。
术语
shell用于执行命令。终端(terminal)是运行shell的包装器。在终端上可以设置字体、字体大小、配色方案以及支持多个选项卡。终端仿真器的示例包括GNOME终端、KDE的Konsole,Terminator和XTerm。对于Linux系统,笔者建议保留默认值。Windows适用Windows Terminal;Mac适用iTerm2。
图源:MartinThoma)
(Linux上的四个终端仿真器(Gnome Terminal、Konsole、XTerm、Terminator)。XTerm不直接支持标签。其他的打开了2个选项卡。它们都运行Bash shell。
系统的Shell包括ZSH、Bash、fish。Windows系统典型的shell是PowerShell。可以通过执行echo $ 0来查看正在运行的shell。Linux系统使用更多的是Bash shell。
图源:Martin Thoma
(在Gnome终端中的三个Linux shell(ZSH、Bash、fish),ZSH shell经过了大量更改;Bash shell和fish shell显示默认值。可见,fish shell具有其他两个shell缺少的内联自动提示功能。)
每个shell都有提示符(prompt)。提示符是光标之前写入的内容。它表示可以输入指令并提供有用的背景信息。在上面的示例中,提示符包含用户名moose,当前计算机pc08 ,当前工作目录 ~/GitHub/MartinThoma/flake8-simplify,活跃git分支feature/19以及进行了±修改的事实。
字体
无论选择哪个,字体都很重要。你可能想要一个等宽字体,相信我一定要安装powerline字体。powerline字体能使shell使用像图像的字符。它可以使提示符效果更好。笔者比较喜欢UbuntuMono和DroidSans Mono:
上面一行是Ubuntu Mono,下面是Droid Sans Mono。二者都不错,Ubuntu Mono略胜一筹。| 图源:Martin Thoma
也有Fira Code、Jetbrains Mono 这样的“编程字体”。笔者不喜欢它们,因为很难识别所写内容。
Windows终端
首先确保已安装Windows终端。启动终端并找到设置。它是这个指下的“小箭头”:
点击“Settings”。| 图源:MartinThoma
可以选择JSON文件随自己喜好而更改。如下:
- // This file was initially generated byWindows Terminal 1.2.2381.0
- // It should still be usable in newerversions, but newer versions might have additional
- // settings, help text, or changes thatyou will not see unless you clear this file
- // and let us generate a new one foryou.
- // To view thedefault settings, hold "alt" while clicking onthe "Settings" button.
- // For documentation on thesesettings, see: https://aka.ms/terminal-documentation
- {
- "$schema": "https://aka.ms/terminal-profiles-schema",
- "defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
- "initialCols": 120,
- "initialRows": 30,
- //Youcanaddmoreglobalapplicationsettingshere.
- //Tolearnmoreaboutglobalsettings,visithttps://aka.ms/terminal-global-settings
- //Ifenabled, selectionsareautomaticallycopiedtoyourclipboard.
- "copyOnSelect": false,
- //Ifenabled,formatteddataisalsocopiedtoyourclipboard
- "copyFormatting": false,
- //Aprofilespecifiesacommandtoexecutepairedwithinformationabouthowitshouldlookandfeel.
- //Eachoneofthemwillappearinthe NewTab dropdown,
- // andcanbeinvokedfromthecommandlinewith`wt.exe-pxxx`
- //Tolearnmoreaboutprofiles,visithttps://aka.ms/terminal-profile-settings
- "profiles":
- {
- "defaults":
- {
- //Putsettingsherethatyouwanttoapplytoallprofiles.
- },
- "list":
- [
- {
- //Makechangesheretothepowershell.exeprofile.
- "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
- "name": "WindowsPowerShell",
- "commandline": "powershell.exe",
- "hidden": false,
- "fontFace": "DejaVuSans Mono for Powerline"
- },
- {
- //Makechangesheretothecmd.exeprofile.
- "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
- "name": "CommandPrompt",
- "commandline": "cmd.exe",
- "hidden": false
- },
- {
- "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
- "hidden": false,
- "name": "Ubuntu",
- "source": "Windows.Terminal.Wsl",
- "fontFace": "DejaVuSans Mono for Powerline",
- "colorScheme": "Solarized Dark",
- },
- {
- "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
- "hidden": false,
- "name": "AzureCloud Shell",
- "source": "Windows.Terminal.Azure"
- }
- ]
- },
- //Addcustomcolorschemestothisarray.
- //Tolearnmoreaboutcolorschemes,visithttps://aka.ms/terminal-color-schemes
- "schemes": [
- {
- "background": "#073642",
- "black": "#073642",
- "blue": "#268BD2",
- "brightBlack": "#002B36",
- "brightBlue": "#839496",
- "brightCyan": "#93A1A1",
- "brightGreen": "#586E75",
- "brightPurple": "#6C71C4",
- "brightRed": "#CB4B16",
- "brightWhite": "#FDF6E3",
- "brightYellow": "#657B83",
- "cyan": "#2AA198",
- "foreground": "#FDF6E3",
- "green": "#859900",
- "name": "Solarized Dark",
- "purple": "#D33682",
- "red": "#D30102",
- "white": "#EEE8D5",
- "yellow": "#B58900"
- },
- {
- "background": "#FDF6E3",
- "black": "#073642",
- "blue": "#268BD2",
- "brightBlack": "#002B36",
- "brightBlue": "#839496",
- "brightCyan": "#93A1A1",
- "brightGreen": "#586E75",
- "brightPurple": "#6C71C4",
- "brightRed": "#CB4B16",
- "brightWhite": "#FDF6E3",
- "brightYellow": "#657B83",
- "cyan": "#2AA198",
- "foreground": "#073642",
- "green": "#859900",
- "name": "Solarized Light",
- "purple": "#D33682",
- "red": "#D30102",
- "white": "#EEE8D5",
- "yellow": "#B58900"
- },
- ],
- //Addcustomkeybindingstothisarray.
- //Tounbindakeycombinationfromyourdefaults.json,setthecommandto"unbound".
- //Tolearnmoreaboutkeybindings,visithttps://aka.ms/terminal-keybindings
- "keybindings":
- [
- //CopyandpasteareboundtoCtrl+Shift+CandCtrl+Shift+Vinyourdefaults.json.
- //ThesetwolinesadditionallybindthemtoCtrl+CandCtrl+V.
- //Tolearnmoreaboutselection, visithttps://aka.ms/terminal-selection
- { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
- { "command": "paste", "keys": "ctrl+v" },
- //PressCtrl+Shift+Ftoopenthesearchbox
- { "command": "find", "keys": "ctrl+shift+f" },
- //PressAlt+Shift+Dtoopenanewpane.
- //-"split":"auto"makesthispaneopeninthedirectionthatprovidesthemostsurfacearea.
- //-"splitMode":"duplicate"makesthenewpaneusethefocusedpane sprofile.
- //Tolearnmoreaboutpanes, visithttps://aka.ms/terminal-panes
- { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" },
- "keys": "alt+shift+d" },
- {"command": "closeTab", "keys": "ctrl+w"},
- {"command": "newTab", "keys": "ctrl+t"}
- ]
- }
下载并安装所有4种“ DejaVu Sans Mono Powerline”字体。在已知的所有系统上,字体安装都是一个流程:双击字体,然后跳出一个有“安装”按钮的窗口。
Linux和Windows终端:Aminal
Aminal是用Go语言编写的终端仿真器。可用于Linux、Windows和Mac。它允许通过配置文件完成颜色、键盘快捷键等配置。首先需要在系统中安装并配置Go语言。Ubuntu的示例如下:
- $ sudo apt-get install golang libgl1-mesa-dev xorg-dev
- $ export GOPATH="$HOME/go"
- $ export GOBIN=$(go env GOPATH)/bin
接着就可以安装并运行aminal了:
- $ go get -u github.com/liamg/aminal
- $ aminal
Linux系统:Gnome终端
可以通过编辑文件来自定义Gnome终端。这里笔者用12号字设置了Ubuntu Mono衍生的powerline常规字体。
图源:Martin Thoma
命令是为了zsh而设置,因为这是笔者最喜欢的shell。
图源:Martin Thoma
颜色设置为solarized dark(从左到右、从上到下)
Linux系统:fish shell
安装fish shell:
- sudo apt-get install fish
更改终端仿真器的默认shell为fish。在Gnome终端叫做“自定义命令”
接着安装“Oh My Fish”:
- curl -L https://get.oh-my.fish | fish
然后将主题设置为agnoster:
- omf install agnoster
- omf theme agnoster
别名
要使终端表现出色,核心部分的命令就要简短。因此为命令创建一个别名,即简短版的原命令。最常见是将目录更改为上一级。假如是在 /home/user/foo/bar中,则要转到 /home/user/foo。大多数shell都必须输入cd .. 。我喜欢将其缩写为 ..。所以别名就是alias ..='cd ..' 。
语法可能不同,具体取决于shell。对于Bash、ZSH和fish:
- alias short= long
在bash中要插入到 ~/.bashrc,ZSH中则是 ~/.zshrc,fish中也不相同。一些别名如下:
- # Shorten things
- alias ..= cd ..
- alias ...= cd ../../
- alias ll= ls -alF
- alias la= ls -A
- alias l= ls -CF
- alias c= clear # If your terminal supports colors, use them!
- alias lsls= ls --color=auto
- alias grepgrep= grep --color=auto
- alias fgrepfgrep= fgrep --color=auto
- alias egrepegrep= egrep --color=auto
- alias diff= colordiff # Works only if you have notify-send
- alias alert= notify-send --urgency=low -i "$([ $? = 0 ] && echoterminal || echo error)" "$(history|tail -n1|sed -e s/^s*[0-9]+s*//;s/[;&|]s*alert$// )"
总结一下:
当前题目:在Windows系统和Linux系统中,如何打造一个好终端?
文章路径:http://www.stwzsj.com/qtweb/news14/11664.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联