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

Multiline prompt #25

Merged
merged 3 commits into from
Jan 19, 2022
Merged
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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,17 @@ Modify variables using `set --universal` from the command line or `set --global`

### Flags

| Variable | Type | Description | Default |
| ------------- | ------- | ----------------------------------- | ------- |
| `hydro_fetch` | boolean | Fetch git remote in the background. | `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` |

### Misc

| Variable | Type | Description | Default |
| ---------------------------- | ------- | -------------------------------------------------------- | ------- |
| `fish_prompt_pwd_dir_length` | numeric | The number of characters to display when path shortening | 1 |


## License

Expand Down
42 changes: 30 additions & 12 deletions conf.d/hydro.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ function $_hydro_git --on-variable $_hydro_git
end

function _hydro_pwd --on-variable PWD
set --local root (command git rev-parse --show-toplevel 2>/dev/null |
string replace --all --regex -- "^.*/" "")
set --global _hydro_pwd (
string replace --ignore-case -- ~ \~ $PWD |
string replace -- "/$root/" /:/ |
string replace --regex --all -- "(\.?[^/]{1})[^/]*/" \$1/ |
string replace -- : "$root" |
string replace --regex -- '([^/]+)$' "\x1b[1m\$1\x1b[22m" |
string replace --regex --all -- '(?!^/$)/' "\x1b[2m/\x1b[22m"
)
set --query fish_prompt_pwd_dir_length || set --local fish_prompt_pwd_dir_length 1
if test "$fish_prompt_pwd_dir_length" -le 0 || test "$hydro_multiline" = true
set --global _hydro_pwd (
string replace --ignore-case -- ~ \~ $PWD |
string replace --regex -- '([^/]+)$' "\x1b[1m\$1\x1b[22m" |
string replace --regex --all -- '(?!^/$)/' "\x1b[2m/\x1b[22m"
)
else
set --local root (command git rev-parse --show-toplevel 2>/dev/null |
string replace --all --regex -- "^.*/" "")
set --global _hydro_pwd (
string replace --ignore-case -- ~ \~ $PWD |
string replace -- "/$root/" /:/ |
string replace --regex --all -- "(\.?[^/]{"$fish_prompt_pwd_dir_length"})[^/]*/" \$1/ |
string replace -- : "$root" |
string replace --regex -- '([^/]+)$' "\x1b[1m\$1\x1b[22m" |
string replace --regex --all -- '(?!^/$)/' "\x1b[2m/\x1b[22m"
)
end
Comment on lines +10 to +28
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place that maybe feels a little kludgy and duplicative to me, but I don't think it will have any impact on performance or usability.

test "$root" != "$_hydro_git_root" &&
set --global _hydro_git_root $root && set $_hydro_git
end
Expand All @@ -38,11 +47,11 @@ end
function _hydro_prompt --on-event fish_prompt
set --local last_status $pipestatus
set --query _hydro_pwd || _hydro_pwd
set --global _hydro_prompt "$_hydro_color_prompt$hydro_symbol_prompt"
set --global _hydro_prompt "$_hydro_newline$_hydro_color_prompt$hydro_symbol_prompt"

for code in $last_status
if test $code -ne 0
set _hydro_prompt "$_hydro_color_error"[(string join "\x1b[2mǀ\x1b[22m" $last_status)]
set _hydro_prompt "$_hydro_newline$_hydro_color_error"[(string join "\x1b[2mǀ\x1b[22m" $last_status)]
break
end
end
Expand Down Expand Up @@ -105,8 +114,17 @@ for color in hydro_color_{pwd,git,error,prompt,duration}
end && $color
end

function hydro_multiline --on-variable hydro_multiline
if test "$hydro_multiline" = true
set --global _hydro_newline "\n"
else
set --global _hydro_newline ""
end
end && hydro_multiline
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mischievous, but I'll allow it, lol. 👍


set --query hydro_color_error || set --global hydro_color_error $fish_color_error
set --query hydro_symbol_prompt || set --global hydro_symbol_prompt ❱
set --query hydro_symbol_git_dirty || set --global hydro_symbol_git_dirty •
set --query hydro_symbol_git_ahead || set --global hydro_symbol_git_ahead ↑
set --query hydro_symbol_git_behind || set --global hydro_symbol_git_behind ↓
set --query hydro_multiline || set --global hydro_multiline false