Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a username/hostname section to the prompt #62

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,23 @@ Modify variables using `set --universal` from the command line or `set --global`

> Any argument accepted by [`set_color`](https://fishshell.com/docs/current/cmds/set_color.html).

| Variable | Type | Description | Default |
| ---------------------- | ----- | ------------------------------ | -------------------- |
| `hydro_color_pwd` | color | Color of the pwd segment. | `$fish_color_normal` |
| `hydro_color_git` | color | Color of the git segment. | `$fish_color_normal` |
| `hydro_color_start` | color | Color of the start symbol. | `$fish_color_normal` |
| `hydro_color_error` | color | Color of the error segment. | `$fish_color_error` |
| `hydro_color_prompt` | color | Color of the prompt symbol. | `$fish_color_normal` |
| `hydro_color_duration` | color | Color of the duration section. | `$fish_color_normal` |
| Variable | Type | Description | Default |
| ---------------------- | ----- | --------------------------------------- | -------------------- |
| `hydro_color_pwd` | color | Color of the pwd segment. | `$fish_color_normal` |
| `hydro_color_git` | color | Color of the git segment. | `$fish_color_normal` |
| `hydro_color_start` | color | Color of the start symbol. | `$fish_color_normal` |
| `hydro_color_error` | color | Color of the error segment. | `$fish_color_error` |
| `hydro_color_prompt` | color | Color of the prompt symbol. | `$fish_color_normal` |
| `hydro_color_duration` | color | Color of the duration section. | `$fish_color_normal` |
| `hydro_color_who ` | color | Color of the username/hostname section. | `$fish_color_normal` |

### Flags

| Variable | Type | Description | Default |
| ----------------- | ------- | -------------------------------------------- | ------- |
| `hydro_fetch` | boolean | Fetch git remote in the background. | `false` |
| `hydro_multiline` | boolean | Display prompt character on a separate line. | `false` |
| Variable | Type | Description | Default |
| ------------------------ | ------- | -------------------------------------------- | ------- |
| `hydro_fetch` | boolean | Fetch git remote in the background. | `false` |
| `hydro_multiline` | boolean | Display prompt character on a separate line. | `false` |
| `hydro_always_show_user` | boolean | Always display username. | `false` |

### Misc

Expand Down
36 changes: 35 additions & 1 deletion conf.d/hydro.fish
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ function _hydro_pwd --on-variable PWD --on-variable hydro_ignored_git_paths --on
)
end

function _hydro_who
set --local show_hostname false
if set --query SSH_CONNECTION
set show_hostname true
else
switch (uname)
case Linux
if test -r /proc/1/environ && grep -qa container=lxc /proc/1/environ
set show_hostname true
end
case FreeBSD
if test "$(sysctl -n security.jail.jailed)" = "1"
set show_hostname true
end
case SunOS
if test "$(zonename)" != "global"
set show_hostname true
end
end
end

if test "$show_hostname" = true
set --local short_host (
string split --fields 1 . $hostname
)
set --global _hydro_who "$USER@$short_host "
else if test "$hydro_always_show_user" = true
set --global _hydro_who "$USER "
else
set --global _hydro_who ""
end
end

function _hydro_postexec --on-event fish_postexec
set --local last_status $pipestatus
set --global _hydro_status "$_hydro_newline$_hydro_color_prompt$hydro_symbol_prompt"
Expand Down Expand Up @@ -60,6 +93,7 @@ end
function _hydro_prompt --on-event fish_prompt
set --query _hydro_status || set --global _hydro_status "$_hydro_newline$_hydro_color_prompt$hydro_symbol_prompt"
set --query _hydro_pwd || _hydro_pwd
set --query _hydro_who || _hydro_who

command kill $_hydro_last_pid 2>/dev/null

Expand Down Expand Up @@ -115,7 +149,7 @@ end

set --global hydro_color_normal (set_color normal)

for color in hydro_color_{pwd,git,error,prompt,duration,start}
for color in hydro_color_{pwd,git,error,prompt,duration,start,who}
function $color --on-variable $color --inherit-variable color
set --query $color && set --global _$color (set_color $$color)
end && $color
Expand Down
2 changes: 1 addition & 1 deletion functions/fish_prompt.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function fish_prompt --description Hydro
echo -e "$_hydro_color_start$hydro_symbol_start$hydro_color_normal$_hydro_color_pwd$_hydro_pwd$hydro_color_normal $_hydro_color_git$$_hydro_git$hydro_color_normal$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal$_hydro_status$hydro_color_normal "
echo -e "$_hydro_color_start$hydro_symbol_start$hydro_color_normal$_hydro_color_who$_hydro_who$hydro_color_normal$_hydro_color_pwd$_hydro_pwd$hydro_color_normal $_hydro_color_git$$_hydro_git$hydro_color_normal$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal$_hydro_status$hydro_color_normal "
end