Code Monkey home page Code Monkey logo

iterm2-dynamicprofileimporter's Introduction

iTerm2-DynamicProfile

Script to import dynamic profile into iTerm2

I have a list of servers I would normally SSH into using iTerm. Managing this long list was a pain and manually organizing them in profiles was not an easy task.

Fortunately, iTerm2 2.9.20140923 and later allows for the creation of Dynamic Profiles.

https://iterm2.com/dynamic-profiles.html

This script was written to allow for simple creation of dynamic Profiles in iTerm2 for those individual hosts.

Usage

Run the following to display the help manual

python iterm_dynamic_profile_importer.py -h

which looks like this:

usage: SCRIPT [-h] [-f FILENAME] [-i CSVIMPORT] [-r] [-t TAGS [TAGS ...]]
              [-l HOSTS [HOSTS ...]] [-c COMMAND]

This script will allow you to automatically create dynamic profiles for iTerm2
version 2.9.20140923 or later.

optional arguments:
  -h, --help            show this help message and exit
  -f FILENAME, --file FILENAME
                        Name of the dynamic profile plist file. File extension
                        is not required.
  -i CSVIMPORT, --import CSVIMPORT
                        CSV (comma separated) file. Two columns are accepted
                        for hostnames/ip address and tags.
  -r, --replace         If set the content of the dynamic profile will be
                        replaced/overwritten.
  -t TAGS [TAGS ...], --tags TAGS [TAGS ...]
                        Tag(s) to apply to the profile.
  -l HOSTS [HOSTS ...], --hosts HOSTS [HOSTS ...]
                        List of host names or IP addresses
  -c COMMAND, --command COMMAND
                        The custom SSH command to run. The host name should be
                        entered as '{host}'
  -a CUSTOMATTRIBUTES, --attributes CUSTOMATTRIBUTES
                        You can specify extra attributes to be added to the
                        profile in JSON. (e.g. "{"Badge Text": "{host}"}")

The only required arguments are -i and -l

Basic run!

CSV Sample

hostname-1, tag1 tag2 tag3
hostname-2, tag3 tag4 tag5

Execute

python iterm_dynamic_profile_importer.py -i /path/to/csv/file/above.csv

This will create a file in ~/Library/Application Support/iTerm2/DynamicProfiles called my-dynamic-profiles.plist

Content of my-dynamic-profiles.plist:

{
    "Profiles": [
        {
            "Command": "ssh hostname-1",
            "Custom Command": "Yes",
            "Guid": "hostname-1",
            "Name": "hostname-1",
            "Tags": [
                "tag1",
                "tag2",
                "tag3"
            ]
        },
        {
            "Command": "ssh hostname-2",
            "Custom Command": "Yes",
            "Guid": "hostname-2",
            "Name": "hostname-2",
            "Tags": [
                "tag3",
                "tag4",
                "tag5"
            ]
        }
    ]
}

New Dynamic Profiles can also be added by specifying the -l hostname argument:

python iterm_dynamic_profile_importer.py -l hostname-3 hostname-4 -t tag-5 tag-6 tag-7 -r
{
    "Profiles": [
        {
            "Command": "ssh hostname-3",
            "Custom Command": "Yes",
            "Guid": "hostname-3",
            "Name": "hostname-3",
            "Tags": [
                "tag-5",
                "tag-6",
                "tag-7"
            ]
        },
        {
            "Command": "ssh hostname-4",
            "Custom Command": "Yes",
            "Guid": "hostname-4",
            "Name": "hostname-4",
            "Tags": [
                "tag-5",
                "tag-6",
                "tag-7"
            ]
        }
    ]
}

NOTE: Running the script without specifying the -r argument will append to the current my-dynamic-profiles.plist. If -r is set, the old dynamic profiles will be wiped and the new ones added. Argument -f could've been set as well to output to a different file.*

iterm2-dynamicprofileimporter's People

Contributors

luis-cano-wpp avatar peloncano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.