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

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*
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
,
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 __INLINE_CODE_14__ and style properties. __INLINE_CODE_15__ formats :
- __INLINE_CODE_16__ to specify __INLINE_CODE_17__
- __INLINE_CODE_18__ to specify __INLINE_CODE_19__
- __INLINE_CODE_20__ or __INLINE_CODE_21__ to specify __INLINE_CODE_22__
- __INLINE_CODE_23__ to specify __INLINE_CODE_24__ and __INLINE_CODE_25__
- __INLINE_CODE_26__ to specify __INLINE_CODE_27__ and __INLINE_CODE_28__
- __INLINE_CODE_29__ to specify __INLINE_CODE_30__ and __INLINE_CODE_31__
- __INLINE_CODE_32__ to specify __INLINE_CODE_33__ and __INLINE_CODE_34__ and __INLINE_CODE_35__
__INLINE_CODE_36__ and __INLINE_CODE_37__ components are strictly compared, __INLINE_CODE_38__ matches if it is included in prompt path: __INLINE_CODE_39__ path will match __INLINE_CODE_40__ and __INLINE_CODE_41__.
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 __INLINE_CODE_42__, __INLINE_CODE_43__, __INLINE_CODE_44__...
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 (__INLINE_CODE_45__) could help.