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

feature single line prompt #265

Merged
merged 49 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
dad0fc6
add flag for compact mode feature
noaccOS Apr 22, 2020
6e00023
document feature flag
edouard-lopez Dec 28, 2020
7d7d2a1
refactor to use long format option and constant
edouard-lopez Dec 28, 2020
b802da4
rename feature to `pure_enable_compact_prompt`
edouard-lopez Dec 28, 2020
45c076f
implement compact-prompt feature
edouard-lopez Dec 28, 2020
874adf4
extract `_pure_print_prompt_rows` function
edouard-lopez Dec 28, 2020
fa5a4c3
query variable before testing it
edouard-lopez Dec 28, 2020
e0d3179
test spacing before prompt symbol in 2-lines and 1-line prompt
edouard-lopez Dec 28, 2020
f0a61d5
rename feature flag as `pure_enable_single_line_prompt`
edouard-lopez Dec 28, 2020
2555009
correct regression
edouard-lopez Dec 28, 2020
b8bff2b
correct CI fails due to leaked variable between tests
edouard-lopez Dec 28, 2020
561cfef
create `purge_configs` and `disable_colors`
edouard-lopez Dec 29, 2020
acd62e4
refactor _pure_prompt tests
edouard-lopez Dec 29, 2020
45e6e01
tests `_pure_set_color` a bit
edouard-lopez Dec 29, 2020
4c4bbe6
prefer import
edouard-lopez Dec 29, 2020
bb07ebf
declare config variables to global scope
edouard-lopez Dec 29, 2020
a81e5fc
purge test variables on every scopes (local/global/universal)
edouard-lopez Dec 29, 2020
998f52c
purge context and disable color for git-related tests
edouard-lopez Dec 29, 2020
4aba62d
test pure_show_jobs colorization separatly and reduce test duration
edouard-lopez Dec 29, 2020
4da9bb7
purge configs and disable colors when testing configs
edouard-lopez Dec 29, 2020
3459f16
print test filename atop of tests
edouard-lopez Dec 29, 2020
5917f31
declare config variable in setup hook for prefix_root_prompt
edouard-lopez Dec 29, 2020
a6d1978
import constants and heplers
edouard-lopez Dec 29, 2020
14abae8
pass variable by value
edouard-lopez Dec 29, 2020
0a19fc5
privatize tests help methods
edouard-lopez Dec 29, 2020
009ec8c
match variables starting with 'pure_' using builtin `string match`
edouard-lopez Dec 29, 2020
8ac4b20
add `_purge_configs` and `_disable_colors` to all remaining test files
edouard-lopez Dec 29, 2020
80733e4
prefer import over mock
edouard-lopez Dec 29, 2020
ceb3afc
remove useless directory removal
edouard-lopez Dec 29, 2020
88b1318
import `_pure_set_color` before tested method
edouard-lopez Dec 29, 2020
2d4ef89
move `_purge_configs` and `_disable_colors` at the end on `setup` to…
edouard-lopez Dec 29, 2020
998ee3e
add a dedicated test to git branch symbol colorization
edouard-lopez Dec 29, 2020
d34367e
revamp `_pure_set_default`
edouard-lopez Dec 29, 2020
402fe4d
switch all test variables to universal scope to prevent hectic failure
edouard-lopez Dec 29, 2020
5ddd3bd
disable color variable at universal scope
edouard-lopez Dec 29, 2020
0a6575f
disable colors in tests by default, enable when required
edouard-lopez Dec 30, 2020
85706de
restore `purge_configs` and `disable_colors` content
edouard-lopez Jan 6, 2021
b4c8614
add a debug-tests file to help understand what's happening
edouard-lopez Jan 6, 2021
24b8283
extract `_pure_is_single_line_prompt`
edouard-lopez Jan 6, 2021
69c9628
source `_pure_set_color` when needed in _pure_prompt.test.fish
edouard-lopez Jan 6, 2021
b5def76
remove new_line before prompt when single prompt is enable
edouard-lopez Jan 6, 2021
4df974e
update list of test files for debug
edouard-lopez Jan 7, 2021
e1a49ff
test `pure_set_color` resolve variable value
edouard-lopez Jan 7, 2021
9c53de4
fix some test color issue by echoing empty string in `_pure_set_color…
edouard-lopez Jan 7, 2021
62aff80
import required module (not mocked)
edouard-lopez Jan 7, 2021
2ce9ecf
use long-format option `--regex`
edouard-lopez Jan 7, 2021
5735de9
udpate list of test files in debug script
edouard-lopez Jan 7, 2021
64ecd36
quiet docker output
edouard-lopez Jan 7, 2021
2c24946
bump version 3.5.0
edouard-lopez Dec 28, 2020
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ or changing the defaults in your `config.fish`:
| **`pure_show_system_time`** | `false` | `true`: shows system time before the prompt symbol (as `%H:%M:%S`). |
| **`pure_threshold_command_duration`** | `5` | Show command duration when above this value (seconds). |
| **`pure_show_prefix_root_prompt`** | `false` | `true`: shows prompt prefix when logged in as `root`. |
| **`pure_enable_single_line_prompt`** | `false` | `true`: Compact prompt as a single line |

### Colors

Expand Down
5 changes: 4 additions & 1 deletion conf.d/pure.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set --global pure_version 3.4.2 # used for bug report
set --global pure_version 3.5.0 # used for bug report

# Base colors
_pure_set_default pure_color_primary blue
Expand Down Expand Up @@ -79,3 +79,6 @@ _pure_set_default pure_check_for_new_release false
_pure_set_default pure_show_prefix_root_prompt false
_pure_set_default pure_symbol_prefix_root_prompt "#"
_pure_set_default pure_color_prefix_root_prompt pure_color_danger

# Compact mode
_pure_set_default pure_enable_single_line_prompt false
2 changes: 1 addition & 1 deletion functions/_pure_check_for_new_release.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function _pure_check_for_new_release \
set latest (pure_get_latest_release_version "rafaelrinaldi/pure")

if test "v"$pure_version != $latest
set --local latest_version (_pure_set_color $pure_color_info)$latest(_pure_set_color pure_color_normal)
set --local latest_version (_pure_set_color $pure_color_info)$latest(_pure_set_color $pure_color_normal)
echo -e "🔔 New version available!\n"
echo -e (_pure_set_color $pure_color_success)"fisher install rafaelrinaldi/pure@$latest_version\n"
end
Expand Down
5 changes: 5 additions & 0 deletions functions/_pure_is_single_line_prompt.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function _pure_is_single_line_prompt \
--description 'Test if single line prompt feature is enabled'
set --query pure_enable_single_line_prompt
and test $pure_enable_single_line_prompt = true
end
4 changes: 2 additions & 2 deletions functions/_pure_prefix_root_prompt.fish
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function _pure_prefix_root_prompt
set --local username (id -u -n) # current user name
set --local prefix_root_prompt ''
set --local prefix_root_prompt

if test $pure_show_prefix_root_prompt = true -a "$username" = "root"
if set --query pure_show_prefix_root_prompt; and test $pure_show_prefix_root_prompt = true -a "$username" = "root"
set --local prefix_color (_pure_set_color $pure_color_prefix_root_prompt)
set prefix_root_prompt "$prefix_color$pure_symbol_prefix_root_prompt"
end
Expand Down
10 changes: 10 additions & 0 deletions functions/_pure_print_prompt_rows.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function _pure_print_prompt_rows \
--description "Manage default vs. compact prompt"

# print current path, git branch/status, command duration
if _pure_is_single_line_prompt
echo -e -n (_pure_prompt_first_line)
else
echo -e (_pure_prompt_first_line)
end
end
15 changes: 14 additions & 1 deletion functions/_pure_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ function _pure_prompt \
set --local pure_symbol (_pure_prompt_symbol $exit_code)
set --local system_time (_pure_prompt_system_time)
set --local root_prefix (_pure_prefix_root_prompt)
set --local space
if _pure_is_single_line_prompt
set space ' '
end

echo (_pure_print_prompt $system_time $root_prefix $jobs $virtualenv $vimode_indicator $pure_symbol)
echo (\
_pure_print_prompt \
$system_time \
$root_prefix \
$jobs \
$virtualenv \
$vimode_indicator \
$space \
$pure_symbol \
)
end
8 changes: 5 additions & 3 deletions functions/_pure_prompt_first_line.fish
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
set --global FAILURE 1

function _pure_prompt_first_line \
--description 'Print contextual information before prompt.'

if not type -fq git # exit if git is not available
return 1
if not type --quiet --no-functions git # exit if git is not available
return $FAILURE
end

set --local prompt_ssh (_pure_prompt_ssh)
Expand All @@ -17,7 +19,7 @@ function _pure_prompt_first_line \
set --local current_folder (_pure_prompt_current_folder $prompt_width)

set --local prompt_components
if test $pure_begin_prompt_with_current_directory = true
if set --query pure_begin_prompt_with_current_directory; and test $pure_begin_prompt_with_current_directory = true
set prompt_components \
$current_folder \
$prompt_git \
Expand Down
2 changes: 1 addition & 1 deletion functions/_pure_prompt_git.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function _pure_prompt_git \
--description 'Print git repository informations: branch name, dirty, upstream ahead/behind'

if test $pure_enable_git != true
if set --query pure_enable_git; and test $pure_enable_git != true
return
end

Expand Down
2 changes: 1 addition & 1 deletion functions/_pure_prompt_jobs.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function _pure_prompt_jobs --description "Display number of running jobs"
if test $pure_show_jobs = true
if set --query pure_show_jobs; and test $pure_show_jobs = true
set --local njobs (count (jobs -p))
set --local jobs_color (_pure_set_color $pure_color_jobs)
if test $njobs -gt 0
Expand Down
2 changes: 1 addition & 1 deletion functions/_pure_prompt_new_line.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function _pure_prompt_new_line \
--on-event fish_prompt

set --local new_line
if test $_pure_fresh_session = false
if not _pure_is_single_line_prompt; and test $_pure_fresh_session = false
set new_line "\n"
end

Expand Down
4 changes: 2 additions & 2 deletions functions/_pure_prompt_symbol.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function _pure_prompt_symbol \
set --local command_succeed 0

set --local symbol_color $symbol_color_success # default pure symbol color
if test $exit_code -ne $command_succeed
if set --query exit_code; and test $exit_code -ne $command_succeed
set symbol_color $symbol_color_error # different pure symbol color when previous command failed

if test "$pure_separate_prompt_on_error" = true
if set --query pure_separate_prompt_on_error; and test $pure_separate_prompt_on_error = true
set symbol_color "$symbol_color_error$prompt_symbol$symbol_color_success"
end
end
Expand Down
2 changes: 1 addition & 1 deletion functions/_pure_prompt_system_time.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function _pure_prompt_system_time --description "Display system time"
if test $pure_show_system_time = true
if set --query pure_show_system_time; and test $pure_show_system_time = true
set --local time_color (_pure_set_color $pure_color_system_time)
echo "$time_color"(date '+%T')
end
Expand Down
2 changes: 1 addition & 1 deletion functions/_pure_prompt_vimode.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function _pure_prompt_vimode
if test $pure_reverse_prompt_symbol_in_vimode = false
if set --query pure_reverse_prompt_symbol_in_vimode; and test $pure_reverse_prompt_symbol_in_vimode = false
echo (fish_default_mode_prompt)
end
end
7 changes: 5 additions & 2 deletions functions/_pure_set_default.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ function _pure_set_default \
--description 'Set default value for configuration variable' \
--argument-names var default

if not set --query --universal $var; or test -z $$var; and not set --query --global $var
set --universal $var $default
set is_available_universally (not set --query --universal $var; or test -z $$var; echo $status)
set is_available_globally (not set --query --global $var; or test -z $$var; echo $status)

if test $is_available_universally -eq 0 -a $is_available_globally -eq 0
set --universal $var "$default"
end
end
3 changes: 2 additions & 1 deletion functions/fish_prompt.fish
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# a called to `_pure_prompt_new_line` is triggered by an event
function fish_prompt
set --local exit_code $status # save previous exit code

echo -e -n (_pure_prompt_beginning) # init prompt context (clear current line, etc.)
echo -e (_pure_prompt_first_line) # print current path, git branch/status, command duration
_pure_print_prompt_rows # manage default vs. compact prompt
_pure_place_iterm2_prompt_mark # place iTerm shell integration mark
echo -e -n (_pure_prompt $exit_code) # print prompt
echo -e (_pure_prompt_ending) # reset colors and end prompt
Expand Down
2 changes: 1 addition & 1 deletion functions/fish_title.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 basename (string replace --regex '^.*/' '' -- $PWD)
set --local current_folder (_pure_parse_directory)
set --local current_command (status current-command 2>/dev/null; or echo $_)

Expand Down
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ usage:
.PHONY: build-pure-on
build-pure-on:
docker build \
--quiet \
--file ./Dockerfile \
--build-arg FISH_VERSION=${FISH_VERSION} \
--tag=pure-on-fish-${FISH_VERSION} \
Expand All @@ -25,6 +26,7 @@ build-pure-on:
dev-pure-on: CMD?=fish
dev-pure-on:
docker run \
--quiet \
--name run-pure-on-${FISH_VERSION} \
--rm \
--interactive \
Expand Down
13 changes: 13 additions & 0 deletions tests/_pure.test.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
source $current_dirname/fixtures/constants.fish
source $current_dirname/../functions/_pure_set_default.fish
@mesg (_print_filename $current_filename)


function setup
_purge_configs
_disable_colors
end

@test "configure: pure_version" (
set --erase pure_version
source $current_dirname/../conf.d/pure.fish
Expand Down Expand Up @@ -271,3 +277,10 @@ source $current_dirname/../functions/_pure_set_default.fish
source $current_dirname/../conf.d/pure.fish
echo $pure_color_prefix_root_prompt
) = pure_color_danger

@test "configure: pure_enable_single_line_prompt" (
set --erase pure_enable_single_line_prompt
source $current_dirname/../conf.d/pure.fish
echo $pure_enable_single_line_prompt
) = false

16 changes: 10 additions & 6 deletions tests/_pure_check_for_new_release.test.fish
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
source $current_dirname/fixtures/constants.fish
source $current_dirname/../functions/_pure_check_for_new_release.fish
@mesg (_print_filename $current_filename)


function _pure_set_color; echo $EMPTY; end # drop coloring during test
function setup
_purge_configs
_disable_colors
end

@test "_pure_check_for_new_release: is disabled" (
set --global pure_check_for_new_release false
set --universal pure_check_for_new_release false

_pure_check_for_new_release
) $status -eq $SUCCESS


@test "_pure_check_for_new_release: nothing when same as latest" (
set --global pure_check_for_new_release true
set --global pure_version 0.0.1
set --universal pure_check_for_new_release true
set --universal pure_version 0.0.1
function curl; echo '"tag_name": "v0.0.1",'; end # mock

_pure_check_for_new_release
) = '🛈 Checking for new release…'

@test "_pure_check_for_new_release: show fisher command to install when enable" (
set --global pure_check_for_new_release true
set --global pure_version 0.0.1
set --universal pure_check_for_new_release true
set --universal pure_version 0.0.1
function curl; echo '"tag_name": "v9.9.9",'; end # mock

set output (_pure_check_for_new_release 2>&1)
Expand Down
7 changes: 7 additions & 0 deletions tests/_pure_format_time.test.fish
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
source $current_dirname/fixtures/constants.fish
source $current_dirname/../functions/_pure_format_time.fish
@mesg (_print_filename $current_filename)


function setup
_purge_configs
_disable_colors
end

set --local threshold 0 # in seconds


@test "_pure_format_time: throws error on negative time" (
set --local negative_duration -1
_pure_format_time $negative_duration $threshold
Expand Down
23 changes: 14 additions & 9 deletions tests/_pure_get_prompt_symbol.test.fish
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
source $current_dirname/fixtures/constants.fish
source $current_dirname/../functions/_pure_get_prompt_symbol.fish
@mesg (_print_filename $current_filename)


function setup
set --global pure_symbol_prompt '❯'
set --global pure_symbol_reverse_prompt '❮'
_purge_configs
_disable_colors
set --universal pure_symbol_prompt '❯'
set --universal pure_symbol_reverse_prompt '❮'
end

function teardown
set fish_key_bindings fish_default_key_bindings
set fish_bind_mode 'default'
end


@test "_pure_get_prompt_symbol: get default symbol ❯" (
set pure_reverse_prompt_symbol_in_vimode false
set --universal pure_reverse_prompt_symbol_in_vimode false

_pure_get_prompt_symbol
) = '❯'

@test "_pure_get_prompt_symbol: get default symbol ❯ when key binding is default" (
set pure_reverse_prompt_symbol_in_vimode true
set --universal pure_reverse_prompt_symbol_in_vimode true
set fish_bind_mode 'insert'
set fish_key_bindings 'fish_default_key_bindings'

_pure_get_prompt_symbol
) = '❯'

@test "_pure_get_prompt_symbol: get default symbol ❯ when bind mode is default" (
set pure_reverse_prompt_symbol_in_vimode true
set --universal pure_reverse_prompt_symbol_in_vimode true
set fish_key_bindings 'fish_default_key_bindings'
set fish_bind_mode 'default'

_pure_get_prompt_symbol
) = '❯'

@test "_pure_get_prompt_symbol: get default symbol ❯ when VI key binding and in insert mode" (
set pure_reverse_prompt_symbol_in_vimode true
set --universal pure_reverse_prompt_symbol_in_vimode true
set fish_bind_mode 'insert'
set fish_key_bindings 'fish_vi_key_bindings'

_pure_get_prompt_symbol
) = '❯'

@test "_pure_get_prompt_symbol: get default symbol ❯ when VI key binding and in replace mode" (
set pure_reverse_prompt_symbol_in_vimode true
set --universal pure_reverse_prompt_symbol_in_vimode true
set fish_bind_mode 'replace'
set fish_key_bindings 'fish_vi_key_bindings'

_pure_get_prompt_symbol
) = '❯'

@test "_pure_get_prompt_symbol: get reverse symbol ❮ when VI key binding and not in insert mode or replace mode" (
set pure_reverse_prompt_symbol_in_vimode true
set --universal pure_reverse_prompt_symbol_in_vimode true
set fish_bind_mode 'default'
set fish_key_bindings 'fish_vi_key_bindings'

_pure_get_prompt_symbol
) = '❮'

@test "_pure_get_prompt_symbol: get reverse symbol ❮ when hybrid key binding and not in insert mode or replace mode" (
set pure_reverse_prompt_symbol_in_vimode true
set --universal pure_reverse_prompt_symbol_in_vimode true
set fish_bind_mode 'default'
set fish_key_bindings 'fish_hybrid_key_bindings'

Expand Down
8 changes: 8 additions & 0 deletions tests/_pure_init.test.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
source $current_dirname/fixtures/constants.fish
@mesg (_print_filename $current_filename)


function setup
_purge_configs
_disable_colors
end


@test "init: _pure_fresh_session" (
set --erase _pure_fresh_session
Expand Down
Loading