Little Known Features of iTerm2

栏目: IT技术 · 发布时间: 6年前

内容简介:If you work in a large codebase, chances are you often need to open commits on Github, or revisions in Phabricator or tickets in your in-house bug tracker. This usually involves copying and pasting an identifier into a URL and opening that in your browser.

iTerm2 has a lot of little-known features that can make development much easier.

Smart Selection

If you work in a large codebase, chances are you often need to open commits on Github, or revisions in Phabricator or tickets in your in-house bug tracker. This usually involves copying and pasting an identifier into a URL and opening that in your browser. For example, you may want to open commit hashes or PRs on Github with a single click. You can make iTerm2 recognize arbitrary ids and take custom actions using them when they are Command-clicked via Smart Selections .

Here are a couple of examples:

Open commits on Github

Little Known Features of iTerm2 .

To make Command-clicking on a commit hash open it in Github, do the following:

  1. Install hub
  2. In your iTerm2 Preferences, go to Profiles -> Advanced -> Smart Selection -> Edit
  3. Click the + button to add a new rule and set the Regular Expression to [0-9a-f]{8,40}
  4. Click on Edit Actions... and add a new action
  5. Set the Action to Run Command...
  6. Set the Parameter to cd "\d" && /usr/local/bin/hub browse -- commit/\0 . You may have to update the path to hub here if you installed it to a different directory.

Once this is done, Command-click on a commit hash in iTerm2 should open it in its respective repository if it exists on Github. You can customize this technique to open PRs and Issues on Github as well.

Open revisions in Phabricator

  1. In your iTerm2 Preferences, go to Profiles -> Advanced -> Smart Selection -> Edit
  2. Click the + button to add a new rule and set the Regular Expression to D[:number:]{5}
  3. Click on Edit Actions... and add a new action
  4. Set the Action to Open URL...
  5. Set the Parameter to https://secure.phabricator.com/\0 or a similar URL for your organization.

Dynamic Profiles

If you work on a project that requires starting a number of terminal sessions in specific conditions, it can get annoying to get your environment running from scratch. iTerm2’s Dynamic Profiles allow you to create custom profiles that can depend on other profiles. You can use this to create a hierarchy of profiles that share your common settings but run different commands on startup.

For example, say your project always needs you to be running npm run build , npm run server and npm run worker during development. You can use dynamic profiles to start iTerm2 with all of these commands running as follows:

  1. Generate four GUIDs by running uuidgen in your terminal four times and copying the results.
  2. Create a file in ~/Library/Application Support/iTerm2/DynamicProfiles with these contents (fill in the parts in <...> ):
    {
      "Profiles": [
     {
       "Name": "Development",
       "Guid": "<guid1>",
       "Dynamic Profile Parent Name": "Default",
       "Working Directory": "<path-to-your-project>",
       "Custom Directory": "Yes"
     },
     {
       "Name": "Build",
       "Guid": "<guid2>",
       "Dynamic Profile Parent Name": "Development",
       "Initial Text": "npm run build"
     },
     {
       "Name": "Server",
       "Guid": "<guid3>",
       "Dynamic Profile Parent Name": "Development",
       "Initial Text": "npm run server"
     },
     {
       "Name": "Worker",
       "Guid": "<guid4>",
       "Dynamic Profile Parent Name": "Development",
       "Initial Text": "npm run worker"
     }
      ]
    }
    
  3. Reload iTerm2

These profiles should now show up in iTerm2 as dynamic profiles. You can then start sessions with these profiles to create a window arrangement and hit Command-Shift-S to save it. Then you can start all of these sessions at any time by just pressing Command-Shift-R or tell iTerm2 to open the arrangement when it starts! Check out https://blog.andrewray.me/how-to-create-custom-iterm2-window-arrangments/ for a detailed guide on window arrangements.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

中国制造2025:产业互联网开启新工业革命

中国制造2025:产业互联网开启新工业革命

夏妍娜、赵胜 / 机械工业出版社 / 2016-2-22 / 49.00

过去20年,是中国消费互联网肆意生长的"黄金20年",诞生了诸如BAT等互联网巨头,而时至今日,风口正逐渐转向了产业互联网。互联网这一摧枯拉朽的飓风,在改造了消费服务业之后,正快速而坚定地横扫工业领域,拉开了产业互联网"关键30年"的大幕。 "中国制造2025"规划,恰是中国政府在新一轮产业革命浪潮中做出的积极举措,是在"新常态"和"供给侧改革"的背景下,强调制造业在中国经济中的基础作用,认......一起来看看 《中国制造2025:产业互联网开启新工业革命》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码