Extension for Hyper.app to configure terminal appearance according to current shell prompt.
Using hpm
hpm install hyper-autoprofile
To install, edit ~/.hyper.js
and add "hyper-autoprofile"
to plugins
:
plugins: [
"hyper-autoprofile",
],
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
}
}
//...
};
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
}
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 specifyuser
'@host'
to specifyhost
'/path/to/directory'
or'/directory'
to specifypath
'user@host'
to specifyuser
andhost
'user@:/path'
to specifyuser
andpath
'@host:/path'
to specifyhost
andpath
'user@host:/path'
to specifyuser
andhost
andpath
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
...
If enabled, ANSI escape sequences are stripped from input before trying to match triggers. See here for more details.
If enabled, debug information is written to the DevTools console
Because of some tricky parsing, this plugin could not detect a shell change immediately. To force its detection, clearing terminal (Ctrl+L
) could help.