I have recently switched over to iTerm2 and love it. I am wondering though if there is a way to use profiles to correspond to what environment/specific machine you are on.
Say if I am doing tasks in one window on my mac the profile is displayed as default, but if I ssh into a machine (lets say dev0), the profile on iTerm will update to profile dev0. Once I've finished with dev0 and call exit, the profile will switch to default again.
I realize one work around is to open up a specific profile whenever I want to ssh into another machine and have a way to distinguish, but if the connection is closed it requires you to notice based off text rather than say the background of the window.
Is this possible? If not how can this feature be added, and is there a way I can contribute?
iTerm2 supports a custom escape code that changes the profile on the fly. Put it in your .bashrc or .bash_profile.
<esc>]50;SetProfile=X^G
where X is the profile. For instance, to change the profile to one called "Foo", us this shell script:
#!/bin/bash
echo -e "\033]50;SetProfile=Foo\a"
To change it back when you log out, put code to change the profile back to default in ~/.bash_logout.
for zsh users
lets say you have 2 profiles, one named mac (for your primary machine) and one for linux (your remote machine)
when entering the session, we need to tell zsh to load our profile
connect to remote linux
in ~/.zshrc add echo -e "\033]50;SetProfile=linux\a"
source your files for immediate effect: source ~/.zshrc
your new theme should be visible within the iterm session.
when exiting the session, we need to tell zsh to switch back to our original profile
connect to remote linux
in linux ~/.zlogout add the following
if [ "$SHLVL" = 1 ]; then
echo -e "\033]50;SetProfile=mac\a"
clear
fi
now you can swap profiles with ease <3.
if you are using bash, i believe the steps are similar but you would instead modify ~/.bashrc and ~/.bash_logout
demo
The latest iTerm2 nightly (Build 2.9.20150329-nightly at the time of writing) allows you to do that easily. You can download it here.
Once you've installed and opened it:
Log in to your remote machine via ssh and click iTerm2 (the app menu) > Install Shell Integration. It will download a script with curl and install it. Do the same on your local machine.
Go to Preferences > Profiles.
Create a new profile for your local machine. Customize it to fit your needs (change background color, name, etc)
Go to the Advanced tab and scroll to the bottom.
In Automatic Profile Switching, click '+' and add the hostname of your local machine. The hostname is the one you get when running echo $HOST on the target machine. It is not always the one you see in your prompt.
Create another profile, this time for your remote machine, and customize it.
Add the hostname of the remote machine in Automatic Profile Switching.
Now, if you ssh into the remote machine, your profile will change, and if you exit out of the ssh session, you will be back to your local profile.
You can combine this solution with #esod's answer seamlessly.
Note: it didn't work for me until I created a profile specifically for the desktop instead of using the default profile.
See the documentation for more info.
step 1:
custom your iterm profile, e.g. dark, light
step 2:
add code before to your shell profile, e.g .bashrc or .zshrc
# Change iterm2 profile. Usage it2prof ProfileName (case sensitive)
it2prof() { echo -e "\033]50;SetProfile=$1\a" }
step 3:
make sense your profile
exec $SHELL -l
step 4:
toggle your iterm theme profile
it2prof dark
it2prof light
I had this same wish and found this can be accomplished in iTerm 2 (Build 1.0.0.20130319) in the application's preferences.
You can assign a profile (say a remote profile) with a different preset than your default preset by going to:
Profiles -> Open Profiles
select the profile and click Edit Profiles...
Go to the Colors Tab and choose a preset for this profile from the list in Load Presets...
Further, I've set up Keys shortcut for different profiles so I can have one iTerm window look different than another window. I did this by:
Creating a new a Profile in Preferences
Creating a new Profile Shortcut Key in Preferences-> Keys whose action is New Window with Profile
My Default profile has a black background but sometimes it helps me to have a white background. I duplicate my Default profile and name the new profile DefaultLight. On my Default profile I go to the Keys tab where I create a new Profile Shortcut Key whose Keyboard Shortcut is ^+cmd+n, whose action is New Window with Profile, and whose Profile is DefaultLight.
After saving the prefrences, cmd+n opens a new window with a black background and ^+cmd+n opens a new window with a white background.
There's also a New Tab with Profile action in the Keyboard Shortcut Keys Preference if you're interested in taking this even further.
In my case, I need to combine Yohaï Berreby's answer with my hosts' setting to implement this feature.
In Automatic Profile Switching, click '+' and add the hostname of your local machine. The hostname is the one you get when running echo $HOST on the target machine. It is not always the one you see in your prompt.
My staging server doesn't set $HOST and host name is :
[devel#alveo-staging ~]$ hostname
alveo-staging
But I can't set the rule with hostname as alveo-staging. Because in fact alveo-staging is just an alias of the real hostname (alveo-staging.xxx), which can be set in /etc/hosts.
So the quick solution to this is to use * wildcards, to set the rule as *staging*.
Then it works.
For Fishell user:
1. Create a fish function:
functions it2prof > ~/.config/fish/functions/it2prof.fish
Add this content to ~/.config/fish/functions/it2prof.fish file and save:
function it2prof
echo -e "\033]50;SetProfile=$argv\a"
end
enjoy your command:
it2prof whatever_profile_you_define
Related
I have a Terminator profile (i.e. different bkgd colors, etc) that I use for production related scripts/consoles, but have to change the profile manually. Is there a way to change the profile at a bash level from within an open terminal window when launching production related scripts?
e.g
set_production_profile
heroku run rails console -a myprodapp
set_default_profile
Using Vagrant under Windows 7, trying to ssh into my VM. If I open cmd and run vagrant ssh, I am given the response:
ssh exectuable not found in any directories in the %PATH% variable, Is an SSH client installed? Try installing Cygwin, MinGW, or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication...
So I add Git to my PATH variable:
set PATH=%PATH%;C:\Program Files (x86)\Git\bin
And I confirm my PATH variable now contains this:
<snip>C:\ProgramData\ComposerSetup\bin;C:\Program Files\cURL\bin;"C:\Program Files (x86)\Git\bin";"C:\Program Files (x86)\Git\cmd";C:\Program Files\nodejs\;C:\HashiCorp\Vagrant\bin
So, I run vagrant ssh again, and it works:
vagrant ssh
Welcome to Ubuntu...
vagrant#mywebsite:~$
But, if I now close my cmd window and reopen it, I can no longer call vagrant ssh. I'm given the same notice I was initially given about not having an SSH client in my PATH variable. What this means is that essentially, I am being re-asked every time to provide an SSH client.
Why?
You have set the variable only for the current command session - you need to set as environment variable
For windows 7
From the Desktop, right-click the Computer icon and select Properties. If you don't have a Computer icon on your desktop, click the Start button, right-click the Computer option in the Start menu, and select Properties.
Click the Advanced System Settings link in the left column.
In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon as shown below. You will end up with something similar as
C:\ProgramData\ComposerSetup\bin;C:\Program Files\cURL\bin;"C:\Program Files (x86)\Git\bin";"C:\Program Files (x86)\Git\cmd";C:\Program Files\nodejs\;C:\HashiCorp\Vagrant\bin
When i use the new Chromium Portable browser it always shows "Google API keys are missing.Some functionality of Chromium Portable will be disabled" after starting up.
How do i get rid of this warning message and what does it mean?.
To get rid of the message...
...on Windows, you can use the command prompt to set the following environment variables to "no":
setx GOOGLE_API_KEY "no"
setx GOOGLE_DEFAULT_CLIENT_ID "no"
setx GOOGLE_DEFAULT_CLIENT_SECRET "no"
Windows' environment variables can also be set from the "Advanced System Settings" tab of the "System" control panel. After setx ... relaunching the browser should no longer have the message. Setting the variables through the "Advanced System Settings" tab may require a log-out before it takes effect.
... on Linux you can use the terminal to set the environment variables to "no" in the bash shell:
export GOOGLE_API_KEY="no"
export GOOGLE_DEFAULT_CLIENT_ID="no"
export GOOGLE_DEFAULT_CLIENT_SECRET="no"
A subsequent launch of the browser from the terminal will not show the missing API key message. To make this setting permanent and to cover invocations from clicking on an icon, follow the directions here for setting environment variables that affect terminal as well as graphical logins.
...on macOS, you can add the following key-value pairs to the LSEnvironment dictionary in Chromium.app > Contents > Info.plist:
<key>LSEnvironment</key>
<dict>
<key>GOOGLE_API_KEY</key>
<string>no</string>
<key>GOOGLE_DEFAULT_CLIENT_ID</key>
<string>no</string>
<key>GOOGLE_DEFAULT_CLIENT_SECRET</key>
<string>no</string>
</dict>
(Note that macOS may have cached the existing Info.plist file, so changes may not take effect immediately. See this answer for some ways around that.)
As for the meaning, I think Dragomir Goranov's answer gives sufficient information.
I needed to get rid of this message too, so I just took what mormegil suggested but applied it to a batch script that launches Chromium.
My below sample batch file will launch Chromium into KIOSK mode but you can just remove the --kiosk if you don't need that.
set GOOGLE_API_KEY="no"
set GOOGLE_DEFAULT_CLIENT_ID="no"
set GOOGLE_DEFAULT_CLIENT_SECRET="no"
"C:\chromium\ChromiumPortable_49.0.2593.0.paf\App\Chromium\32\chrome.exe" --kiosk
I did it this way since I don't want to set those environment variables to affect other instances of Chromium but rather just the one that I'm launching with my batch script.
It means that some functionality will not work. For example "Chrome Sync API" requires API keys.
For more information you can check this URL: http://www.chromium.org/developers/how-tos/api-keys
If something is not clear to you after you read the provided information, please specify exactly what.
Disabling API Key will disable functionality like SYNC. A better solution is to use Google API Keys that LINUX Chromium Browser comes with.
Paste the following into command window on Windows:
setx GOOGLE_API_KEY "AIzaSyCkfPOPZXDKNn8hhgu3JrA62wIgC93d44k"
setx GOOGLE_DEFAULT_CLIENT_ID "811574891467.apps.googleusercontent.com"
setx GOOGLE_DEFAULT_CLIENT_SECRET "kdloedMFGdGla2P1zacGjAQh"
on Linux:
export GOOGLE_API_KEY="AIzaSyCkfPOPZXDKNn8hhgu3JrA62wIgC93d44k"
export GOOGLE_DEFAULT_CLIENT_ID="811574891467.apps.googleusercontent.com"
export GOOGLE_DEFAULT_CLIENT_SECRET="kdloedMFGdGla2P1zacGjAQh"
Restart Chromium, and you are all set.
On macOS another (simpler) solution is:
/usr/bin/env GOOGLE_API_KEY="no" GOOGLE_DEFAULT_CLIENT_ID="no" GOOGLE_DEFAULT_CLIENT_SECRET="no" /usr/bin/open -a chromium
as open passed existing environment variable to the launched application (see man open).
PS: I would have preferred to add that as a comment... but I can't as stackoverflow told me that I don't have enough reputation.
For LINUX users, for some reason if you want to use the raw build straight out of a compile without packaging, add these lines (on top) to the chrome-wrapper file present in the directory.
export GOOGLE_API_KEY="no"
export GOOGLE_DEFAULT_CLIENT_ID="no"
export GOOGLE_DEFAULT_CLIENT_SECRET="no"
and execute chrome by cd to the directory and ./chrome-wrapper and not ./chrome
Make sure you make the necessary changes in the chromium-devel.desktop which maybe in ~/.local/share/applications/ so as to run from the bash script and not from the executable.
I made a mistake in my gnome terminal configuration. I entered a command to start with in the preferences, but that command fails, and now all I get is a window that opens and closes right away, and I basically can't use gnome terminal anymore :-( Is there any way I can remove the configuration file and restart fresh??
Thanks!
Open the XTerm (Standard terminal for linux) and enter this command
gnome-terminal -e bash
It opens the gnome-terminal. Open profile preferences and configure your terminal to "Hold the terminal open".
Editing preferences
$HOME/.gconfd/saved_state
the above file might be of interest depending on exactly what configuration you changed. Of course, it holds configuration from other programs as well.
If you are on the newer gnome terminal that uses dconf, it's a little trickier, but still doable:
Profiles are stored with a UUID, you need to find the UUID of the profile to remove:
dconf dump /org/gnome/terminal/ | less
Search for a visible-name='...' entry matching the profile you want to remove. Look above that for the section header like [legacy/profiles:/:...]. The full name of the item you want to delete is thus /org/gnome/terminal/legacy/profiles:/:.... Delete it thus:
dconf reset -f /org/gnome/terminal/legacy/profiles:/:...
Side note: This Q&A probably should be moved to unix.stackexchange.com.
Is it possible to open a terminal window with 3 tabs. Each tab should have different path.
Example:
Tab1: /etc
Tab2: /bin
Tab3: /www/ tail -f file.txt
This is absolutely possible, but it will take some work on your part. The first thing you need is to set up each window/tab you want in your Settings:
I have 4 tabs that I open automagically every time I open Terminal. DB Shell, Editor, Server, and Shell. These are all within the Sasquatch (don't ask) project, thus the naming. Each of these should then have a unique command associated with them:
In this case, I'm executing vim. If you happen to have a specific directory you'd like to start off in, you can use something like vim ~/projects/main/. Really whatever you want to go in there is the command the shell will execute when it opens. Now you need to open all your windows/tabs:
Close everything.
Open a new window for each of your profiles.
Go to the Shell menu => New Tab/New Window => Select the profile you created above.
Repeat for each window or tab you want.
Once you have all of your windows and/or tabs open, save them as a Window Group.
Go to the Window menu => Save Window As Group....
Give your Window Group a name (this is helpful later).
If you want this group to open every time you open Terminal, check the box at the bottom of this screen, and then hit save.
Close out of all of your Windows/Tabs (time to test it!).
Open your new Window Group.
Go to the Window menu => Open Window Group => Select the group you just made.
This should pop up all the windows you just had, in the same position. Each of the commands you set up in Settings should be launched in their respective tabs.
As of Mac OS X Lion 10.7, Terminal makes this much easier to do, without creating new profiles for each command.
By default, Terminal will remember and restore the current working directory for each terminal in a Window Group. (If the working directory has been communicated to Terminal using an escape sequence. The default shell, bash, will do this at every command prompt. For other shells, you'll need to adapt the code in /etc/bashrc.)
If you create a terminal with Shell > New Command, Terminal will automatically run that command when a Window Group is opened. Terminal will automatically run a limited set of "safe" commands†, and when saving a Window Group there's an option to run all commands in the group.
Terminal also automatically does these for all windows when restarting Terminal with Resume enabled. So, you may not even have to create a Window Group, depending on your circumstances.
For your example case:
Use Shell > New Command to run "tail -f /www/file.txt".
Create a new tab and "cd /etc".
Create a new tab and "cd /bin".
Save them with Window > Save Windows as Group. Be sure to check the "Restore all commands" checkbox.
Each time you open that Window Group, it will recreate those windows and run the commands. If you need to run a command and specify the starting directory, in the New Command dialog check the "Run command inside a shell" checkbox and make the command "cd ; ".
Also note that you can tell Terminal to open your Window Group at startup with Terminal > Preferences > Startup > On startup, open > Window group. There's even a checkbox to set this when saving a new Window Group.
† The "safe" commands include anything listed in /etc/shells, plus: screen, tmux, emacs, vi/vim, nano, pico, and top. You can customize the list with "defaults write com.apple.Terminal RestorableCommands". Set it to an array of strings containing command names or full paths. Some commands have parameters that are "unsafe" to run automatically without user intervention, so by default these commands are only considered "safe" if they do not have any arguments. To make a command safe to run with arguments, add an asterisk, e.g., "top *" is in the default value for this preference.
You can do what you wish from within Terminal.
If in Terminal preferences (Settings tab) you create a new profile (or copy one with Duplicate Settings), you can then set each profile to run a command on startup (the "Shell" subgroup within the profile).
Then setup your tabs by using the Shell > New Tab menu to create the new tabs from each of the specific profiles that you created for the three different executables.
Then do the Save Window Group to save the group of tabs (and it will save their profiles as well).
I suggest the use if iTerm instead of Terminal. If only because it is more configurable. You can script it, but more important to you is that you can create a bookmark folder (one for each tab) and then "open in tabs" which will give you the behavior you seek.
I suspect you can control commands to be executed too. One of the programs I use creates a single-tab terminal window and arranges to execute a profile-setting script before continuing to the command prompt - the same should be feasible for a multi-tab terminal. The file is a MacOS X properties XML file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CommandString</key>
<string>. /Applications/IBM/informix/demo/server/profile_settings</string>
<key>FontAntialias</key>
<false/>
<key>RunCommandAsShell</key>
<false/>
<key>ShowShellCommandInTitle</key>
<true/>
<key>TerminalType</key>
<string>xterm</string>
<key>WindowTitle</key>
<string>IDS Command Window</string>
<key>name</key>
<string>IDS Command Window</string>
<key>type</key>
<string>Window Settings</string>
</dict>
</plist>
You can click on it and the terminal window is launched, the profile settings are set, and then you have a command prompt to type at. Presumably, changing the 'dot' command into the 'tail' command of the question would work; it might be that the 'RunCommandAsShell' key set to '<true\>' would replace the normal shell with the command - which is perhaps more appropriate for the question.
Another way of doing this is by using the Elscripto ruby gem: https://github.com/Achillefs/elscripto. It allows yuo to easily specify terminal tabs using a YAML file
Open the tabs you want and set each one up as you wish, i.e. in tab 1, cd /etc, tab 2 cd /bin and so on. Now go to Window > Save Windows as Group. Click the checkbox 'Use window group when Terminal starts' and hey presto!
http://www.iterm2.com/#/section/features/split_panes
"Divide a tab up into multiple panes, each one of which shows a different session. You can slice vertically and horizontally and create any number of panes in any imaginable arrangement."
How to Create Custom iTerm2 Window Arrangements
Create a custom keyboard shortcut to automatically spawn a set of windows and splits with processes running.
With a shortcut cmd+shift+w transform split your window arrangement into 3 panels
https://www.youtube.com/watch?v=Rg8AT-nds1Q