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

More customizations #103

Merged
merged 17 commits into from
Jan 8, 2019
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
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,51 @@ You can tweak pretty much everything in `pure` by overriding variables in your `

```fish
# Symbols
_pure_set_default pure_symbol_prompt "❯"
set pure_symbol_prompt "❯"

# Git
_pure_set_default pure_symbol_git_down_arrow "⇣"
_pure_set_default pure_symbol_git_up_arrow "⇡"
_pure_set_default pure_symbol_git_dirty "*"
set pure_symbol_git_arrow_down "⇣"
set pure_symbol_git_arrow_up "⇡"
set pure_symbol_git_dirty "*"

# Title
_pure_set_default pure_symbol_horizontal_bar "—"

# Colors
_pure_set_default pure_color_red (set_color red)
_pure_set_default pure_color_green (set_color green)
_pure_set_default pure_color_blue (set_color blue)
_pure_set_default pure_color_magenta (set_color magenta)
_pure_set_default pure_color_yellow (set_color yellow)
_pure_set_default pure_color_cyan (set_color cyan)
_pure_set_default pure_color_gray (set_color 93A1A1)
_pure_set_default pure_color_normal (set_color normal)

_pure_set_default pure_username_color $pure_color_gray
_pure_set_default pure_host_color $pure_color_gray
_pure_set_default pure_root_color $pure_color_normal
set pure_symbol_horizontal_bar "—"

# Base colors
set pure_color_blue (set_color blue)
set pure_color_cyan (set_color cyan)
set pure_color_gray (set_color 93A1A1)
set pure_color_magenta (set_color magenta)
set pure_color_normal (set_color normal)
set pure_color_red (set_color red)
set pure_color_white (set_color white)
set pure_color_yellow (set_color yellow)

# Colors used on symbols, attributes and events
set pure_color_command_duration (set_color --background blue)
set pure_color_error (set_color magenta)
set pure_color_git_arrows $pure_color_cyan
set pure_color_git_branch $pure_color_gray
set pure_color_git_dirty $pure_color_gray
set pure_color_ssh_host $pure_color_gray
set pure_color_ssh_separator $pure_color_gray
set pure_color_ssh_user_normal $pure_color_gray
set pure_color_ssh_user_root $pure_color_white
set pure_color_success (set_color green)
set pure_color_virtualenv $pure_color_gray

# Print current working directory at the beginning of prompt
# true (default): current directory, git, user@hostname (ssh-only), command duration
# false: user@hostname (ssh-only), current directory, git, command duration
_pure_set_default pure_prompt_begin_with_current_directory true
set pure_prompt_begin_with_current_directory true

# Show exit code of last command as a separate prompt character (cf. https://github.com/sindresorhus/pure/wiki#show-exit-code-of-last-command-as-a-separate-prompt-character)
# false - single prompt character, default
# true - separate prompt character
_pure_set_default pure_separate_prompt_on_error false
set pure_separate_prompt_on_error false

# Max execution time of a process before its run time is shown when it exits
_pure_set_default pure_command_max_exec_time 5
set pure_command_max_exec_time 5
```

## Tests
Expand Down
32 changes: 21 additions & 11 deletions conf.d/pure.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,36 @@ set -gx VIRTUAL_ENV_DISABLE_PROMPT 1
_pure_set_default pure_symbol_prompt "❯"

# Git
_pure_set_default pure_symbol_git_down_arrow "⇣"
_pure_set_default pure_symbol_git_up_arrow "⇡"
_pure_set_default pure_symbol_git_arrow_down "⇣"
_pure_set_default pure_symbol_git_arrow_up "⇡"
_pure_set_default pure_symbol_git_dirty "*"

# Title
_pure_set_default pure_symbol_horizontal_bar "—"

# Colors
_pure_set_default pure_color_red (set_color red)
_pure_set_default pure_color_green (set_color green)
# Base colors
_pure_set_default pure_color_blue (set_color blue)
_pure_set_default pure_color_magenta (set_color magenta)
_pure_set_default pure_color_yellow (set_color yellow)
_pure_set_default pure_color_cyan (set_color cyan)
_pure_set_default pure_color_gray (set_color 93A1A1)
_pure_set_default pure_color_gray (set_color brblack)
_pure_set_default pure_color_magenta (set_color magenta)
_pure_set_default pure_color_normal (set_color normal)
_pure_set_default pure_color_red (set_color red)
_pure_set_default pure_color_white (set_color white)
_pure_set_default pure_color_yellow (set_color yellow)

_pure_set_default pure_username_color $pure_color_gray
_pure_set_default pure_host_color $pure_color_gray
_pure_set_default pure_root_color $pure_color_normal
# Colors used on symbols, attributes and events
_pure_set_default pure_color_command_duration $pure_color_yellow
_pure_set_default pure_color_current_folder $pure_color_blue
_pure_set_default pure_color_git_arrows $pure_color_cyan
_pure_set_default pure_color_git_branch $pure_color_gray
_pure_set_default pure_color_git_dirty $pure_color_gray
_pure_set_default pure_color_ssh_host $pure_color_gray
_pure_set_default pure_color_ssh_separator $pure_color_gray
_pure_set_default pure_color_ssh_user_normal $pure_color_gray
_pure_set_default pure_color_ssh_user_root $pure_color_white
_pure_set_default pure_color_symbol_error $pure_color_red
_pure_set_default pure_color_symbol_success $pure_color_magenta
_pure_set_default pure_color_virtualenv $pure_color_gray

# Print current working directory at the beginning of prompt
# true (default): current directory, git, user@hostname (ssh-only), command duration
Expand Down
21 changes: 12 additions & 9 deletions fish_title.fish
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Set title to current folder and shell name
function fish_title
set -l basename (string replace -r '^.*/' '' -- $PWD)
set -l current_folder (_pure_parse_directory)
set -l command $argv[1]
set -l prompt "$basename: $command $pure_symbol_horizontal_bar $_"

if test -z "$command"
set prompt "$current_folder $pure_symbol_horizontal_bar $_"
function fish_title \
--description "Set title to current folder and shell name" \
--argument-names last_command

set --local basename (string replace -r '^.*/' '' -- $PWD)
set --local current_folder (_pure_parse_directory)
set --local current_command (status current-command 2>/dev/null; or echo $_)

set --local prompt "$basename: $last_command $pure_symbol_horizontal_bar $current_command"

if test -z "$last_command"
set prompt "$current_folder $pure_symbol_horizontal_bar $current_command"
end

echo $prompt
Expand Down
6 changes: 0 additions & 6 deletions functions/_pure_prompt_at.fish

This file was deleted.

2 changes: 1 addition & 1 deletion functions/_pure_prompt_command_duration.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function _pure_prompt_command_duration
if test -n "$CMD_DURATION"
set command_duration (_pure_format_time $CMD_DURATION $pure_command_max_exec_time)
end
set --local command_duration_color "$pure_color_yellow"
set --local command_duration_color "$pure_color_command_duration"

echo "$command_duration_color$command_duration"
end
2 changes: 1 addition & 1 deletion functions/_pure_prompt_current_folder.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function _pure_prompt_current_folder --argument-names current_prompt_width
if test -z "$current_prompt_width"; return $fail; end

set --local current_folder (_pure_parse_directory (math $COLUMNS - $current_prompt_width - 1))
set --local current_folder_color "$pure_color_blue"
set --local current_folder_color "$pure_color_current_folder"

echo "$current_folder_color$current_folder"
end
6 changes: 3 additions & 3 deletions functions/_pure_prompt_first_line.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function _pure_prompt_first_line \
end

set --local prompt (_pure_print_prompt \
(_pure_prompt_user_and_host) \
(_pure_prompt_ssh) \
(_pure_prompt_git) \
(_pure_prompt_command_duration)
)
Expand All @@ -18,11 +18,11 @@ function _pure_prompt_first_line \
set prompt_components \
(_pure_prompt_current_folder $prompt_width) \
(_pure_prompt_git) \
(_pure_prompt_user_and_host) \
(_pure_prompt_ssh) \
(_pure_prompt_command_duration)
else
set prompt_components \
(_pure_prompt_user_and_host) \
(_pure_prompt_ssh) \
(_pure_prompt_current_folder $prompt_width) \
(_pure_prompt_git) \
(_pure_prompt_command_duration)
Expand Down
6 changes: 3 additions & 3 deletions functions/_pure_prompt_git_arrows.fish
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ function _pure_prompt_git_arrows
set --local commit_to_pull $git_status[2]

if test $commit_to_push -gt 0 # upstream is behind local repo
set git_arrows "$pure_symbol_git_up_arrow"
set git_arrows "$pure_symbol_git_arrow_up"
end

if test $commit_to_pull -gt 0 # upstream is ahead of local repo
set git_arrows "$git_arrows$pure_symbol_git_down_arrow"
set git_arrows "$git_arrows$pure_symbol_git_arrow_down"
end

set git_arrows_color "$pure_color_cyan"
set git_arrows_color "$pure_color_git_arrows"
end

echo "$git_arrows_color$git_arrows"
Expand Down
2 changes: 1 addition & 1 deletion functions/_pure_prompt_git_branch.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function _pure_prompt_git_branch
set --local git_branch (_pure_parse_git_branch) # current git branch
set --local git_branch_color "$pure_color_gray"
set --local git_branch_color "$pure_color_git_branch"

echo "$git_branch_color$git_branch"
end
4 changes: 3 additions & 1 deletion functions/_pure_prompt_git_dirty.fish
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
function _pure_prompt_git_dirty
set --local git_dirty_symbol
set --local git_dirty_color

set --local is_git_dirty (command git status --porcelain --ignore-submodules 2>/dev/null)
if test -n "$is_git_dirty" # untracked or un-commited files
set git_dirty_symbol "$pure_symbol_git_dirty"
set git_dirty_color "$pure_color_git_dirty"
end

echo "$git_dirty_symbol"
echo "$git_dirty_color$git_dirty_symbol"
end
5 changes: 5 additions & 0 deletions functions/_pure_prompt_ssh.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function _pure_prompt_ssh
if test "$SSH_CONNECTION" != ""
echo (_pure_prompt_ssh_user)(_pure_prompt_ssh_separator)(_pure_prompt_ssh_host)
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function _pure_prompt_host
function _pure_prompt_ssh_host
set --query --global hostname
or set --local hostname (hostname --short) # current host name
set --local hostname_color "$pure_host_color"
set --local hostname_color "$pure_color_ssh_host"

echo "$hostname_color$hostname"
end
end
6 changes: 6 additions & 0 deletions functions/_pure_prompt_ssh_separator.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function _pure_prompt_ssh_separator
andreiborisov marked this conversation as resolved.
Show resolved Hide resolved
set --local separator_symbol "@"
set --local separator_symbol_color "$pure_color_ssh_separator"

echo "$separator_symbol_color$separator_symbol"
end
9 changes: 9 additions & 0 deletions functions/_pure_prompt_ssh_user.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function _pure_prompt_ssh_user
set --local username (whoami) # current user name
andreiborisov marked this conversation as resolved.
Show resolved Hide resolved
set --local username_color "$pure_color_ssh_user_normal" # default color
if test "$username" = "root"
set username_color "$pure_color_ssh_user_root" # different color for root
end

echo "$username_color$username"
end
8 changes: 4 additions & 4 deletions functions/_pure_prompt_symbol.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function _pure_prompt_symbol \
set --local pure_symbol $pure_symbol_prompt
set --local command_succeed 0

set --local color_symbol $pure_color_green # pure symbol is green by default
set --local color_symbol $pure_color_symbol_success # default pure symbol color
if test $exit_code -ne 0
set color_symbol $pure_color_red # pure symbol is red when previous command failed
set color_symbol $pure_color_symbol_error # different pure symbol color when previous command failed

if test $pure_separate_prompt_on_error = true
set color_symbol "$pure_color_red$pure_symbol_prompt$pure_color_magenta"
if test $pure_separate_prompt_on_error = true
set color_symbol "$pure_color_symbol_error$pure_symbol_prompt$pure_color_symbol_success"
end
end

Expand Down
10 changes: 0 additions & 10 deletions functions/_pure_prompt_user.fish

This file was deleted.

5 changes: 0 additions & 5 deletions functions/_pure_prompt_user_and_host.fish

This file was deleted.

2 changes: 1 addition & 1 deletion functions/_pure_prompt_virtualenv.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function _pure_prompt_virtualenv --description "Display virtualenv directory"
if test -n "$VIRTUAL_ENV"
set --local virtualenv (basename "$VIRTUAL_ENV")
set --local virtualenv_color "$pure_color_gray"
set --local virtualenv_color "$pure_color_virtualenv"

echo "$virtualenv_color$virtualenv"
end
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/_pure_prompt.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ set --local succeed 0

test "print prompt after succeeding command"
(
set pure_color_green (set_color green)
set pure_color_symbol_success (set_color magenta)
set pure_symbol_prompt '>' # using default ❯ break following tests
set --local last_command $succeed

_pure_prompt $last_command
) = (set_color green)'>'
) = (set_color magenta)'>'
end

test "print prompt after failing command"
(
set pure_color_red (set_color red)
set pure_color_symbol_error (set_color red)
set pure_symbol_prompt '>' # using default ❯ break following tests
set --local last_command $failed

Expand Down
17 changes: 0 additions & 17 deletions tests/_pure_prompt_at.test.fish

This file was deleted.

4 changes: 2 additions & 2 deletions tests/_pure_prompt_command_duration.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set --local empty ''
test "hide command duration when it's zero"
(
set CMD_DURATION $empty
set pure_color_yellow $empty
set pure_color_command_duration $empty

_pure_prompt_command_duration
) = $empty
Expand All @@ -16,7 +16,7 @@ test "displays command duration when non-zero"
(
set CMD_DURATION 6000 # in milliseconds
set pure_command_max_exec_time 5 # in seconds
set pure_color_yellow $empty
set pure_color_command_duration $empty

_pure_prompt_command_duration
) = '6s'
Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_current_folder.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

test "returns _pure_prompt_current_folder"
(
set pure_color_blue $empty
set pure_color_current_folder $empty
set COLUMNS 20
set current_prompt_width 10

Expand Down
Loading