Skip to content

Extension for Hyper.app to configure terminal appearance according to current shell prompt

License

Notifications You must be signed in to change notification settings

chabou/hyper-autoprofile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hyper-autoprofile

CI Status NPM version Downloads Conventional Commits

Extension for Hyper.app to configure terminal appearance according to current shell prompt.

AutoProfile Demo

Install

Using hpm

hpm install hyper-autoprofile

Manually

To install, edit ~/.hyper.js and add "hyper-autoprofile" to plugins:

plugins: [
  "hyper-autoprofile",
],

Configuration

Add autoProfile in your ~/.hyper.js config. The configuration below shows the two differents sections prompts and profiles:

module.exports = {
  config: {
    // other configs...
    autoProfile: {
      prompts: [
        {
          // 'MyHost:Documents me$ ' default MacOS bash prompt
          pattern: "^(\\S+):(.*) ([a-z_][a-z0-9_\\-\\.]*[\\$]?)[\\$#]\\s*$",
          hostname: 1,
          path: 2,
          username: 3
        },
        {
          // 'me@MyHost:~$ ' default Linux bash prompt
          pattern:
            "^([a-z_][a-z0-9_\\-\\.]*[\\$]?)@(\\S+):([\\/~].*)[\\$#]\\s*$",
          username: 1,
          hostname: 2,
          path: 3
        },
        {
          // 'me@MyHost ~> ' default fish prompt
          pattern: "^([a-z_][a-z0-9_\\-\\.]*[\\$]?)@(\\S+) ([\\/~].*)[>#]\\s*",
          username: 1,
          hostname: 2,
          path: 3
        },
        {
          // 'MyHost% ' default zsh prompt
          pattern: "^(\\S+)% ",
          hostname: 1
        },
        {
          // '➜  ~' default oh-my-zsh prompt (robbyrussell theme)
          pattern: "^➜  ([\\/~].*) ",
          path: 1
        },
        {
          // 'me@MyHost MINGW64 ~ (master) ' default git-bash prompt on Windows
          pattern: "^([a-z_][a-z0-9_\\-\\.]*[\\$]?)@(\\S+) MINGW64 ([\\/~].*)(\s|$)",
          username: 1,          
          hostname: 2,          
          path: 3        
        }
      ],
      profiles: [
        {
          triggers: ["root@"],
          backgroundColor: "#400"
        },
        {
          triggers: ["@scotchbox"],
          backgroundColor: "#040"
        },
        {
          triggers: ["/project"],
          backgroundColor: "#004"
        }
      ],
      stripAnsiSequences: true, //default
      debug: false //default
    }
  }
  //...
};

autoProfile.prompts

This section defines different patterns for parsing prompt components: username, host, path.

Note that pattern is a string literal passed to the RegExp() constructor, so remember to escape backslashes in your regexp. For example, if you used a site like regex101.com to verify that your regexp /\[(\w+):\s*(\w+)\](\s*\$)/ is correct, you would double each backslash and write the pattern as:

pattern: '\\[(\\w+):\\s*(\\w+)\\](\\s*\\$)',

The values for hostname, username, and pattern are indexes into the match array returned by RegExp#exec.

For example, define a pattern for MacOS bash default prompt:

{
  // 'MyHost:~ me$ '
  pattern: '^(\\S+):([/~].*) ([a-z_][a-z0-9_\\-\\.]*[\\$]?)[\\$#]\\s*$',
  hostname: 1,
  path: 2,
  username: 3
}

autoProfile.profiles

This section is an ordered array of potential Profile. A Profile is composed by a list of trigger and style properties. trigger formats :

  • 'user@' to specify user
  • '@host' to specify host
  • '/path/to/directory' or '/directory' to specify path
  • 'user@host' to specify user and host
  • 'user@:/path' to specify user and path
  • '@host:/path' to specify host and path
  • 'user@host:/path' to specify user and host and path

user and host components are strictly compared, path matches if it is included in prompt path: '/tmp' path will match '/tmp' and '/path/to/tmp/subpath'.

All other properties of this section will be applied to Term if a trigger is matched. It could be any property of the main config section like backgroundColor, cursorColor, fontSize...

autoProfile.stripAnsiSequences (Default: true)

If enabled, ANSI escape sequences are stripped from input before trying to match triggers. See here for more details.

autoProfile.debug (Default: false)

If enabled, debug information is written to the DevTools console

Caveat

Because of some tricky parsing, this plugin could not detect a shell change immediately. To force its detection, clearing terminal (Ctrl+L) could help.

Licence

MIT

About

Extension for Hyper.app to configure terminal appearance according to current shell prompt

Resources

License

Stars

Watchers

Forks

Packages

No packages published