android 激发亮度_如何使用有用的小脚本激发可怕的终端

android 激发亮度

by Vijayabharathi Balasubramanian

通过Vijayabharathi Balasubramanian

如何使用有用的小脚本激发可怕的终端 (How to energize your scary terminal with helpful little scripts)

I’m going to talk about three valuable tools that will finally help conquer your fear of terminals: Git Aliases, Bash Aliases, and One click snippets.

我将讨论三种有价值的工具,这些工具最终将帮助您克服对终端的恐惧:Git别名,Bash别名和一键式摘录。

A combination of aliases and bash scripts can make you very productive in your development workflow. Use it long enough and you’ll even forget the original commands beneath the aliases. Which isn’t actually a bad thing — until you get a shiny new laptop and have no idea where you placed your aliases in the old one :)

别名和bash脚本的组合可以使您在开发工作流程中非常高效。 使用它足够长的时间,您甚至会忘记别名下的原始命令。 这实际上不是一件坏事–直到您有了一台闪亮的新笔记本电脑,而且不知道将别名放在旧笔记本电脑的位置为止:)

You may have used Git aliases. You might find bash aliases new. But, don’t miss the gif showing one-click icons at work towards the end. Those one-click desktop icons are my line of defense. They help me dive straight into coding/writing before the harmless “top visited” list on the browser’s new tab can send me off track.

您可能使用了Git别名。 您可能会发现bash别名是新的。 但是,千万不要错过显示一键式图标的gif 。 这些一键式桌面图标是我的防线。 他们帮助我直接进行编码/编写工作,然后浏览器新标签上的无害“ 访问量最大 ”列表可以使我偏离正常轨道。

By the way, I’m using Firefox’s nightly and it is easy to set up a clean slate as your new tab. All right, down to business.

顺便说一句,我每天晚上都在使用Firefox,很容易将干净的面板设置为新标签。 好吧,正事。

1:Git别名 (1: Git Aliases)

If terminal is the dungeon to people new to tech, Git tends to be the darkest passage, intimidating with long stretches of commands.

如果终端是技术新手的地牢,那么Git往往是最黑暗的通道,它被漫长的命令吓倒了。

But, Git is beautiful. Try this game.

但是,Git很漂亮。 试试这个游戏

Part of making git easier to use is setting up your own aliases. That is, once you understand the underlying commands. This is not to give you all the useful aliases. Instead, I’ll point you towards the possibilities so that you can build your own list of aliases.

使git更易于使用的一部分是设置自己的别名。 也就是说,一旦您了解了基本命令。 这并不是要给您所有有用的别名。 相反,我将为您指出可能性,以便您可以构建自己的别名列表。

飞行独奏 (Flying Solo)

Let’s say you are hacking on your own. You stage and commit all day, maybe your code or your writings for the blog. You’ll find a bunch of aliases very useful.

假设您正在自行入侵。 您整天上演并投入精力,也许是您的代码或博客文章。 您会发现很多别名非常有用。

git config --global alias.s statusgit config --global alias.aa 'add --all'git config --global alias.cm 'commit -am'git config --global alias.up 'push'

Make sure you have a well defined .gitignore to avoid tracking unnecessary files such as node_modules. This will help you when you use git aa to stage all files.

确保您具有定义良好的.gitignore以避免跟踪不必要的文件,例如node_modules 。 当您使用git aa所有文件时,这将为您提供帮助。

All these aliases are stored in a config file under home directory. Take a look into ~/.gitconfig. You can even edit the config file directly — just make sure you don’t trip it off.

所有这些别名都存储在主目录下的配置文件中。 看一下~/.gitconfig 。 您甚至可以直接编辑配置文件-只需确保不要将其绊倒即可。

代码协作 (Code Collaboration)

When you are collaborating with a team, a whole other list of commands may be useful. Remember, rebase rewrites history. It is advised only for local branches, to clean up your code on top of remote branch.

当您与团队合作时,其他所有命令列表可能会很有用。 请记住,rebase会重写历史记录。 建议仅本地分支使用 ,以清除远程分支上的代码。

git config --global alias.pr 'pull --rebase upstream master'

Here is one from Harry about aliasing blame to praise and other nuggets that you may find useful.

这是哈利(Harry)的一本关于混叠blamepraise和您可能会发现有用的其他掘金的文章。

高级别名 (Advanced Aliases)
git config --global alias.ls 'log --pretty=format:"%C(yellow)%h %C(green)%s %Creset(%ad)" --date=relative'

%C(yellow) marks the token following the color code in red. In our case above, %h stands for the commit hash, which will be painted yellow on our terminal. %Creset, without brackets, takes you back to default terminal font color. --date=relative tells you days/weeks ago instead of an actual date.

%C(yellow)标记标记为颜色代码后的红色。 在上面的例子中, %h代表提交哈希,它将在我们的终端上显示为黄色。 %Creset(不带括号)将您带回默认的终端字体颜色。 --date=relative告诉您days/weeks ago的日期,而不是实际日期。

All those words may try hard to explain how it looks, but here it is:

所有这些单词可能会尽力解释它的外观,但是这里是:

参考文献 (References)

You can learn more about decorating in git-scm.com. There is a whole bunch of information that you can extract such as %h, %n and so on. By the way, that’s a whole free book on Git. Start from page 1.

您可以在git-scm.com中了解有关装饰的更多信息。 您可以提取大量信息,例如%h%n等。 顺便一下, 那是一本关于Git的完整免费书籍 。 从第1页开始。

I learned a lot of useful tricks from Nicola a while back from his 2014 Atlassian summit talk. I couldn’t find the video, but I found his slide. Don’t miss that anonymous function within aliases.

早在2014年Atlassian峰会演讲中,我就从Nicola那里学到了很多有用的技巧。 我找不到视频,但找到了他的幻灯片 。 不要错过别名中的匿名函数。

Here is a list of his Git aliases. But, in his own words, do not just copy aliases. Build them as you go, adding only the aliases that are useful to you. Otherwise, it’ll just be like spending hours curating articles/books that we’ll never read.

这是他的G it别名的列表。 但是,以他自己的话来说,不要仅仅复制别名。 随便构建它们,仅添加对您有用的别名。 否则,就好比花几个小时来整理我们从未读过的文章/书。

2:Bash别名 (2: Bash Aliases)

Git is not the only command line interface (CLI) that asks for some typing on the terminal. Think about bundle exec rails db:migrate on a terminal or docker-compose exec npm run script that you run on a container. How about something shorter?

Git不是唯一要求在终端上进行键入的command line interface (CLI)。 考虑在终端上docker-compose exec npm run script bundle exec rails db:migrate或在容器上docker-compose exec npm run script 。 矮些的怎么样?

If you use commands that are longer, on a daily basis, consider setting up bash aliases.

如果每天使用更长的命令,请考虑设置bash别名。

The syntax is very simple.

语法非常简单。

alias new_cmd='never-ending-command; and another command'

You add this at the end of the .bashrc file in your home folder. Normally ~/.bashrc is where it is located. The recent one I have set up is for docker commands. It should serve as an example.

您可以将其添加到主文件夹中.bashrc文件的末尾。 通常~/.bashrc是它所在的位置。 我最近设置的是针对docker命令的。 它应该作为一个例子。

alias dc='docker-compose'alias de='docker-compose exec' alias up='cd ~/Projects/docker_project/; dc up'

I used to log out and log back in to make it work on terminals. However, this cool command from Stackoverflow rescued me. Run this on your terminal and start using new aliases right away: source ~/.bashrc

我曾经注销并重新登录以使其在终端上运行。 但是,来自S tackoverflow的这个很酷的命令救了我。 在您的终端上运行它,并立即开始使用新别名: source ~/.bashrc

Are you thinking what I am thinking? Forget about Git aliases? What do we name bash alias for git pull --rebase upstream master? How about gprum?

你在想我在想什么吗? 忘记Git别名了吗? 我们为git pull --rebase upstream master命名bash别名是什么? gprum怎么gprum

Go wild! Be cautious not to reuse existing commands. For example, df shows free disk space in Linux, so I wouldn’t use that as an alias for anything else.

去野外! 注意不要重用现有命令。 例如, df显示Linux中的可用磁盘空间,因此我不会将其用作其他任何东西的别名。

3:一键式摘录 (3: One-Click Snippets)

My favorites. One click, on your custom designed desktop icon, with your own logo, and you’ll have these ready to roll:

我最喜欢的。 在您的自定义设计的桌面图标上单击一下,带有您自己的徽标,您将可以滚动使用这些图标:

  • Opens your project folder in VS Code/atom

    在VS Code / atom中打开您的项目文件夹
  • A terminal running dev server on one tab

    终端在一个选项卡上运行开发服务器
  • Another tab running tests / hot reloading

    另一个标签正在运行测试/热装
  • Last tab that opens with Git status

    最后一个带有Git状态的标签页
  • The last tab stays open for you to git things done.

    最后一个选项卡保持打开状态,为您git事情做好。

  • If your dev server doesn’t open browser, you can open it here

    如果您的开发服务器没有打开浏览器,则可以在此处打开它

There is something magical when you can just tap on an icon and the entire environment springs up for you. One tap and you get your text editor, web server and tests running already.

当您只需点击一个图标,整个环境如雨后春笋般涌现时,这真是神奇。 一键式安装,您的文本编辑器,Web服务器和测试已在运行。

The bash file get-to-work.sh looks like this. By the way, this is on Linux.

bash文件get-to-work.sh看起来像这样。 顺便说一下,这是在Linux上。

#!/bin/bashexport WD="~/development"code $WD gnome-terminal \ --tab --working-directory=$WD \ -e 'bash -c "export BASH_POST_RC=\"npm start\"; exec bash"' \ --tab --working-directory=$WD \ -e 'bash -c "export BASH_POST_RC=\"npm run watch\"; exec bash"' \ --tab --working-directory=$WD \ -e 'bash -c "export BASH_POST_RC=\"git status\"; exec bash"'

We have a working directory set up under variable WD. Then starts a very long line that folds for 7 lines on a terminal width of 80 characters. Don’t let it scare you. If you watch closely, we are opening gnome-terminal with three tabs and running three different commands on them.

我们在变量WD下设置了一个工作目录。 然后开始一条很长的线,该线在80个字符的终端宽度上折叠7行。 不要让它吓到你。 如果您仔细观察,我们将打开带有三个选项卡的gnome-terminal,并在它们上运行三个不同的命令。

Run this command to mark the bash script executable.

运行此命令以标记bash脚本可执行文件。

chmod +x get-to-work.sh

You can already check if the script is working. cd into the folder where you have the shell script and type this on your terminal.

您已经可以检查脚本是否正常工作。 cd进入拥有shell脚本的文件夹,然后在终端上键入此内容。

./get-to-work.sh

Let’s add a nice desktop icon to our script. Exec and Icon are important. They need to be in a .desktop file. I’ve named mine as get-to-work.desktop.

让我们在脚本中添加一个漂亮的桌面图标。 ExecIcon很重要。 它们必须位于.desktop文件中。 我已将我的名字命名为get-to-work.desktop

By the way, this is for Linux. Most of the desktops use freedesktop specification. Reading between the lines, I might have broken a few guidelines (such as not removing any fields even if they are not applicable).

顺便说一下,这是针对Linux的。 大多数桌面使用freedesktop规范。 在两行之间阅读时,我可能违反了一些准则(例如,即使它们不适用也不要删除任何字段)。

[Desktop Entry] Name=Get To Work Comment=Start coding in an instant. GenericName=Development Environment Exec=/home/username/snippets/get-to-work.sh Icon=/usr/share/icons/logo.png Type=Application Terminal=true StartupNotify=true Categories=Utility;

Remember to use the correct path instead of /home/username/.... Make sure you place the Icon in an accessible folder where you have permission to at least read the file.

切记使用正确的路径而不是/home/username/... 确保将Icon放置在您有权访问至少要读取文件的文件夹中。

Validate and install the .desktop file.

验证并安装.desktop文件。

desktop-file-validate get-to-work.desktop desktop-file-install get-to-work.desktop

In case you have permission issues, it is better to install it locally, like this:

如果遇到权限问题,最好将其安装在本地,如下所示:

desktop-file-install get-to-work.desktop --dir=.local/share/applications

That’s it. You’ll have your logo ready as an application within your launcher. You can set it up in the dock too.

而已。 您将在启动器中准备好徽标作为应用程序。 您也可以在扩展坞中进行设置。

观看操作中的一键式图标 (Watch One-click Icon in Action)

Here is a gif showing my recent one-click script.

这是显示我最近的一键式脚本的gif图像。

A larger one, 2.6MB, can be found here if you want to take a closer look.

一个更大的,2.6MB,可以发现在这里如果你想仔细看看。

Here is one more I use to start writing my blog.

这是我用来开始撰写博客的另一种方法。

  • Opens up blog folder on VS code

    在VS代码上打开博客文件夹
  • Loads up localhost on firefox

    在Firefox上加载localhost

  • Opens up hugo server on terminal

    在终端上打开hugo server

Unlike the previous example, in this one, I use the elementary OS and default pantheon-terminal that comes with it. But this doesn’t open multiple tabs, and I haven’t figured out how to make pantheon-terminal do it (like we saw earlier with gnome-terminal ). That little & at the end of firefox gives control back to the script. Otherwise, my terminal wouldn’t open until I close firefox.

与前面的示例不同,在此示例中,我使用基本操作系统和附带的默认pantheon-terminal 。 但这并没有打开多个选项卡,而且我还没有弄清楚如何使pantheon-terminal做到这一点(就像我们之前看到的gnome-terminal )。 firefox末尾的那个小&将控制权交还给脚本。 否则,直到我关闭firefox ,我的终端才会打开。

#!/bin/bash  export WORK_DIR="~/pineboat" /opt/firefox/firefox localhost:1313 & code $WORK_DIR pantheon-terminal -e 'bash -c "cd $WORK_DIR;hugo server -wvFD"'

Finally, I’ve setup a desktop file with the logo of my blog. Pretty sweet, isn’t it?

最后,我设置了一个带有博客徽标的桌面文件。 很漂亮,不是吗?

Hope that was useful and saves few keystrokes. Clap/Share/Tweet to let your network know, if you think they’ll enjoy this post. Any issues, log it under this github issue. Or in the conversations below.

希望这是有用的,并且可以节省一些击键。 如果您认为他们会喜欢这篇文章,请通过Clap / Share / Tweet通知您的网络。 任何问题,请将其记录在此github问题下 。 或在下面的对话中。

Thanks for your time and attention!

感谢您的时间和关注!

Originally published at www.pineboat.in — an uncharted island in the internet.

最初发布在www.pineboat.in上 -互联网上一个未知的岛屿。

翻译自: https://www.freecodecamp.org/news/how-to-energize-your-scary-terminal-with-helpful-little-scripts-c5ae92c12bfe/

android 激发亮度

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值