command-linextermitermiterm2256color

How to set xterm-256colors on iTerm2 via script / command line


In iTerm2 we can set the xterm-256color option by going to Preferences -> Profiles -> Terminal -> Terminal Emulation -> Report Terminal Type and chosing xterm-256color

I want to add to my dotfile's installation script so I don't have to change it manually. Is there a way of setting this option via command line? Maybe via iTerm itself or maybe via apple's defaults write.....

Thank you!


Solution

  • default works only if the setting is a top level key, for example

    [admin@mb-125:~] : defaults read com.googlecode.iterm2 | grep -i promptonquit
        PromptOnQuit = 1;
    [admin@mb-125:~] : defaults write com.googlecode.iterm2 PromptOnQuit -bool FALSE
    [admin@mb-125:~] : defaults read com.googlecode.iterm2 | grep -i promptonquit
        PromptOnQuit = 0;
    

    xterm-256color is part of a dictionary, and we need to use plistbuddy to change it, here is the command to see the current settings

    [admin@mb-125:~] : /usr/libexec/PlistBuddy -c "Print :\"New Bookmarks\":0:\"Terminal Type\"" Library/Preferences/com.googlecode.iterm2.plist 
    xterm-256color
    

    And this is how you change it from command line

    [admin@mb-125:~] : /usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:\"Terminal Type\" xterm" Library/Preferences/com.googlecode.iterm2.plist 
    [admin@mb-125:~] : /usr/libexec/PlistBuddy -c "Print :\"New Bookmarks\":0:\"Terminal Type\"" Library/Preferences/com.googlecode.iterm2.plist 
    xterm