Code Monkey home page Code Monkey logo

iterm2-tab-set's Introduction

Tabset

Have a lot of iTerm2 windows open? They all look nearly indistinguishable? When you go to the Window menu to select one, they're confusingly all entitled "Shell"? tabset can help.

tabset makes life easier for iTerm2 users, enabling easy setting of tab and window titles, badges, and colors. If you have a lot of tabs/windows in operation simultaneously, tabset helps to visually distinguish them.

example tab

Installation

npm install -g iterm2-tab-set

(Depending on local security settings, you may need to use sudo npm ... to authorize global installation.) This will install the tabset command.

Usage

The easiest usage is just to run the command:

tabset

This will colorize the tab header, set the tab title, and set the tab badge based on the current working directory. If all you want are tabs to look a little different from each other, you're done.

For a little more precision, you can give a "tag" to use instead of the current working directory. Perhaps one related to the kind of work you're doing:

tabset html

Different tags will create different-looking tabs.

More Precise Usage

If you want more control of what tabset is setting, and how, read on.

tabset --color <colorspec>

where names or defines acolor, will set the tab header to that color. By default tabset knows all the CSS color names, and how to interpret CSS-style rgb() and hex (e.g. #663399) color definitions. You can add new color names if you like (see below).

If a color name is partially given (e.g. alice), the corresponding color will be guessed (e.g. aliceblue). If more than one named color shares that name fragment, the possible matches will be listed, and one of them will be chosen at random. Note that fragments that exactly match a color name (e.g. blue) will not trigger a search; if you want to search on all all possible blues, use a string like blu that isn't itself an actual color name.

You can see all of the color names with:

tabset --colors

Special color names also recognized include random (chooses a known named color at random) and RANDOM (chooses an RGB color completely at random, not just from the named color palette).

If you choose to define your color precisely with RGB (e.g. rgb(102,51,153)) or hex (e.g. #663399) color specs, note that quotes are probably needed to avoid Unix shell ugliness. That's especially true for rgb() colors, and true of hex specs if the optional but traditional # prefix is used.

If you want to visually pick a color rather than specify it textually:

tabset --pick

Will launch the Mac color picker and set the color based on its result.

example of pick

In many cases, you may not care exactly what color is chosen, just that like terminal tabs are similarly colored. In this case, you can use hashed color option.

tabset --hash <word>

will choose a color based on a hash of <word>. So if you want all your JavaScript coding tabs to have one color, tabset --hash js will do the trick. Other words such as css, html, and server can be used for other tabs and windows. Any string can be used. Case is significant. If you don't like the hashed selection, experiment with variations. You might hate --hash js, but find --hash js_, --hash JS or --hash javascript to be just right

Titles and Badges

Beyond being distinguished by header color, iTerm2 tabs can have titles and badges. Titles appear in either the tab bar or as the window title. Badges are a large-font watermark that appears behind the tab's normal content. (Badges require iTerm2 Version 3 or later.)

tabset --badge "server 1"

Sets the badge watermark to "server 1". The quotes are needed to manage the Unix shell argument handling. Single word badges and titles do not need to be quoted, but any that include spaces should be. You can also embed newlines with \n. Unicode characters are also possible (easiest with cut-and-paste, since Unicode codepoints are difficult to specify in many shells).

iTerm2 defines some variables that badges can live-display. For example, to track the current working directory:

tabset --badge '\(session.path)'

For more of these, see the iTerem 2 docs.

To set tab titles:

tabset --title server

iTerm2 has a complex system for setting tab title, window title, or both, controlled with a mode flag. You can specify this with --mode values of 0, 1, or 2, if you are so inclined. The default, modeless operation will often suffice.

Config File

If you want to add your own named colors, create a JSON file in your home directory called .tabset.

Give it a colors map, like so:

{
  "colors": {
    "alisongreen": "rgb(125,199,53)",
    "js": "orchid",
    "html": "gold",
    "server": "alisongreen",
    "papayawhip": null
  }
}

Now new colors are defined for js, html, and other names. They can be defined in terms of existing color names (making them, in effect, aliases), or through direct rgb() or hex CSS formats.

Once you've added a named color, you use it just like you would use one of the predefined CSS color names. For example here a color alisongreen is defined, then the server color refers to alisongreen. The only restriction is that color names must be defined before they are used.

If you really don't like a color and do not want it included in your palette, remove it from service by defining its value as null. The example above nixes papayawhip.

You can also redefine the default color, using the key default.

The fastest way to get going with your own named colors is:

tabset --init

Which will create a sample .tabset in your $HOME directory if it does not already exist.

tabset also provides commands to make selecting and update custom color names easier.

tabset --add python "rgb(9,3,199)"

Will do the trick. Or to visually select the color:

tabset --add python --pick

Will bring up the Mac color picker, and set the result as your named color.

tabset --del python

Will remove that custom definition. And

tabset --list

Will list out all currently-defined custom colors. (There are many online resources for exploring the base set of CSS named colors. For example, this one.)

example of list

Shortcuts

All of the major options can be abbreviated. tabset --badge js can be said as just tabset -b js. Similarly for -c instead of --color, -h instead of --hash, -p for --pick, and -t instead of --title.

Finally, there is an --all or -a all-in-one option that sets the color, badge, and title simultaneously. This is where it's especially helpful to define named colors for the types of tabs you masy want. You don't even really need to specify the -a flag; if no flag is provided, --all is assumed.

tabset js

For example will label everything it can find with "js" and set the js color. If no color named js is defined, a hashed color will be guessed.

You can also mix and match. E.g.:

tabset js -t one.js

Makes everything js, except the title which is one.js. Conversely

tabset js -b one.js

Sets everything to js except the badge, which reflects the file name.

Mix and match to suit your workflow.

iterm2-tab-set's People

Contributors

jonathaneunice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

iterm2-tab-set's Issues

Need to run tabset twice to set tab title in iterm2 3.3.0 and 3.3.1

After updating iterm to 3.3.0 or 3.3.1 when I run tabset with only a tag name ('tabset foo') the badge and tab colors are set correctly, but does not update the tab title. Running the same tabset command again does work. Running just tabset -t to set the title alone works fine.

I found that swapping the order of calls to setBadge and setTabTitle in tabset.js around line 117 (in the 'if (args.all)' block of current trunk) fixes the problem. I'd be happy to submit this as a pull request, but I feel like I've fixed the problem with no actual understanding of how and why it works so I'm a little reluctant.

Error after I added custom color

After i added a custom color to save, I'm getting this error

tabset --add 321 "rgb(255,203,11)"

none of the tabset commands is working

Screen Shot 2021-08-26 at 03 50 09

Add a --reset option

This would issue the reset command to revert the color back to default in iTerm2:

echo -e "\033]6;1;bg;*;default\a"

Stop ssh from renaming my tab?

Hi!
First of all, thanks for your work on this, I'm just trying it out but it seems to fit my needs really well and seems well thought-out and documented.

This is a request that probably can't be featured in your code, but maybe you have found some kind of solution for it: can you stop ssh from renaming the tabs?

I used to rename my tabs with a simple function in my profile, and had the problem then as well, I'm just wondering if you found a solution for this.

Many thanks in advance.

Add an option to disable text output to the console

I use this tool in a precmd/prexec hook with ZSH so it runs every time my prompt is rendered. When I'm using the --hash option, the text "hashed color: xxx" is rendered to my terminal. It'd be nice to be able to disable this output so it doesn't clutter my screen.

tabset not working when called from expect script

I am trying to run tabset from an expect script.My sequence is

  • open a new iterm2 tab
  • invoke my script to connect to the remote host via ssh
  • script tries to run "tabset" commands using "exec" command in expect to set tab parameters
    • exec tabset --color green
    • exec tabset --title $fhost
    • exec tabset --badge $fhost
      ($fhost is hostname of the remote host stored in variable "fhost")
  • next script spawns a session to remote device

However, I don't see the settings of my iterm2 tab changing after running tabset

Am I missing anything? I am using bash shell to invoke the script.

Thanks in advance.

unable to set tab title when under zsh

tabset clearly works for setting the badge but it doesn't for setting the title, at least not for zsh users.

I suspect it may be a problem specific to my local configuration but after spending a lot of time trying to find the source of the problem I decided to raise a bug. Hopefully we will find it and document the correct way to enable it.

PS. Nice work! It was a pleasure to discover the tool, I had something written in bash but not as polished as yours.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.