您好,登录后才能下订单哦!
这篇文章主要介绍“在Windows系统和Linux系统中怎么打造一个好终端”,在日常操作中,相信很多人在在Windows系统和Linux系统中怎么打造一个好终端问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”在Windows系统和Linux系统中怎么打造一个好终端”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
术语
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(从左到右、从上到下)
背景: #2e3436 / #555753
深红: #cc0000 / 浅红: ef2929
深绿: #4e9a06 / 浅绿: #8ae234
深黄: #c4a000 / 浅黄: #fce94f
深蓝: #3465a4 / 浅蓝: #729fcf
深紫: #75507b / 浅紫: #ad7fa8
深蓝绿: #06989a / 浅蓝绿: #34e2e2
深灰: #d3d7cf /浅灰: #eeeeec
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系统中怎么打造一个好终端”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。