spaceship-prompt 4.4.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/lib/core.zsh +43 -32
- package/lib/hooks.zsh +4 -16
- package/lib/worker.zsh +67 -0
- package/package.json +1 -1
- package/sections/crystal.zsh +41 -0
- package/sections/deno.zsh +44 -0
- package/spaceship.zsh +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [4.5.0](https://github.com/spaceship-prompt/spaceship-prompt/compare/v4.4.0...v4.5.0) (2022-09-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **crystal:** Include Crystal in order ([d215797](https://github.com/spaceship-prompt/spaceship-prompt/commit/d215797efc63e081cc6516aac6974a1ece6b255a))
|
|
7
|
+
* fix grep unknown option: --color ([#1206](https://github.com/spaceship-prompt/spaceship-prompt/issues/1206)) ([8a16414](https://github.com/spaceship-prompt/spaceship-prompt/commit/8a16414d78a41e0e11574c55e323bef09835a77b)), closes [#1066](https://github.com/spaceship-prompt/spaceship-prompt/issues/1066)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **crystal:** Add Crystal section for 4.x ([c72c6c9](https://github.com/spaceship-prompt/spaceship-prompt/commit/c72c6c94f74b0ab1e110c775cfb8ec655b90da0e))
|
|
13
|
+
* **deno:** Add Deno section ([c43f8c5](https://github.com/spaceship-prompt/spaceship-prompt/commit/c43f8c5e4e3886f0ba612c1b347591bcc2b00880))
|
|
14
|
+
|
|
1
15
|
## [4.4.1](https://github.com/spaceship-prompt/spaceship-prompt/compare/v4.4.0...v4.4.1) (2022-09-21)
|
|
2
16
|
|
|
3
17
|
|
package/lib/core.zsh
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
# Tools for loading sections, building sections and invoking the renderer
|
|
4
4
|
# ------------------------------------------------------------------------------
|
|
5
5
|
|
|
6
|
-
# Unique array of async jobs
|
|
7
|
-
typeset -ahU SPACESHIP_JOBS=()
|
|
8
|
-
|
|
9
6
|
# Loads the sections from files and functions
|
|
10
7
|
# USAGE:
|
|
11
8
|
# spaceship::core::load_sections
|
|
@@ -32,17 +29,14 @@ spaceship::core::load_sections() {
|
|
|
32
29
|
done
|
|
33
30
|
|
|
34
31
|
if $load_async; then
|
|
35
|
-
|
|
36
|
-
builtin source "$SPACESHIP_ROOT/async.zsh"
|
|
37
|
-
spaceship::precompile "$SPACESHIP_ROOT/async.zsh"
|
|
38
|
-
}
|
|
32
|
+
spaceship::worker::load
|
|
39
33
|
fi
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
# Iterate over sections, start async jobs and store results in cache
|
|
43
37
|
# USAGE:
|
|
44
|
-
# spaceship::core::
|
|
45
|
-
spaceship::core::
|
|
38
|
+
# spaceship::core::start
|
|
39
|
+
spaceship::core::start() {
|
|
46
40
|
# Clear the cache before every render
|
|
47
41
|
spaceship::cache::clear
|
|
48
42
|
|
|
@@ -56,19 +50,44 @@ spaceship::core::build_cache() {
|
|
|
56
50
|
# spaceship::core::async_callback
|
|
57
51
|
spaceship::core::async_callback() {
|
|
58
52
|
local job="$1" ret="$2" output="$3" exec_time="$4" err="$5" has_next="$6"
|
|
59
|
-
local section
|
|
60
|
-
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
local section="${job#"spaceship_"}" # TODO: Move spaceship_ to a constant
|
|
54
|
+
|
|
55
|
+
# Notify the worker that the job is done
|
|
56
|
+
spaceship::worker::callback "$@"
|
|
57
|
+
|
|
58
|
+
case $job in
|
|
59
|
+
"[async]")
|
|
60
|
+
# Handle all the errors that could indicate a crashed async worker.
|
|
61
|
+
# See zsh-async documentation for the definition of the exit codes.
|
|
62
|
+
if (( code == 2 )) || (( code == 3 )) || (( code == 130 )); then
|
|
63
|
+
# Our worker died unexpectedly, try to recover immediately.
|
|
64
|
+
spaceship::worker::init
|
|
65
|
+
spaceship::core::start
|
|
66
|
+
return
|
|
67
|
+
fi
|
|
68
|
+
;;
|
|
69
|
+
"[async/eval]")
|
|
70
|
+
if (( code )); then
|
|
71
|
+
# Looks like eval failed, rerun async tasks just in case.
|
|
72
|
+
spaceship::core::start
|
|
73
|
+
return
|
|
74
|
+
fi
|
|
75
|
+
;;
|
|
76
|
+
";")
|
|
77
|
+
# Ignore the async evals used to alter worker environment
|
|
78
|
+
return
|
|
79
|
+
;;
|
|
80
|
+
*)
|
|
81
|
+
# Hanlde regular successfully finished jobs
|
|
82
|
+
# Skip prompt re-rendering if section is empty
|
|
83
|
+
if [[ "$(spaceship::cache::get $section)" == "$output" ]]; then
|
|
84
|
+
return
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
# Update section cache
|
|
88
|
+
spaceship::cache::set "$section" "$output"
|
|
89
|
+
;;
|
|
90
|
+
esac
|
|
72
91
|
|
|
73
92
|
# Refresh async section when the last async job has finished
|
|
74
93
|
if [[ "${#SPACESHIP_JOBS}" -eq 0 ]]; then
|
|
@@ -76,13 +95,6 @@ spaceship::core::async_callback() {
|
|
|
76
95
|
spaceship::core::render
|
|
77
96
|
fi
|
|
78
97
|
|
|
79
|
-
# Skip prompt re-rendering if section is empty
|
|
80
|
-
if [[ "$(spaceship::cache::get $section)" == "$output" ]]; then
|
|
81
|
-
return
|
|
82
|
-
fi
|
|
83
|
-
|
|
84
|
-
spaceship::cache::set "$section" "$output"
|
|
85
|
-
|
|
86
98
|
if [[ "$has_next" == 0 ]]; then
|
|
87
99
|
spaceship::core::render
|
|
88
100
|
fi
|
|
@@ -112,8 +124,7 @@ spaceship::core::refresh_section() {
|
|
|
112
124
|
fi
|
|
113
125
|
|
|
114
126
|
if spaceship::is_section_async "$section" && [[ -z $sync ]]; then
|
|
115
|
-
|
|
116
|
-
async_job "spaceship" "spaceship_${section}"
|
|
127
|
+
spaceship::worker::run "spaceship_$section"
|
|
117
128
|
else
|
|
118
129
|
spaceship::cache::set "$section" "$(spaceship_$section)"
|
|
119
130
|
fi
|
|
@@ -150,5 +161,5 @@ spaceship::core::render() {
|
|
|
150
161
|
# .reset-prompt: bypass the zsh-syntax-highlighting wrapper
|
|
151
162
|
# https://github.com/sorin-ionescu/prezto/issues/1026
|
|
152
163
|
# https://github.com/zsh-users/zsh-autosuggestions/issues/107#issuecomment-183824034
|
|
153
|
-
zle .reset-prompt && zle -R
|
|
164
|
+
zle && zle .reset-prompt && zle -R
|
|
154
165
|
}
|
package/lib/hooks.zsh
CHANGED
|
@@ -39,18 +39,10 @@ prompt_spaceship_precmd() {
|
|
|
39
39
|
spaceship_exec_time_stop
|
|
40
40
|
|
|
41
41
|
# Restarts the async worker, in order to get an update-to-date shell environment
|
|
42
|
-
|
|
43
|
-
SPACESHIP_JOBS=()
|
|
44
|
-
# restart worker
|
|
45
|
-
async_stop_worker "spaceship"
|
|
46
|
-
async_start_worker "spaceship" -n -u
|
|
47
|
-
# setopt before call register to avoid callback by async_worker_eval
|
|
48
|
-
async_worker_eval "spaceship" 'setopt extendedglob'
|
|
49
|
-
async_register_callback "spaceship" "spaceship::core::async_callback"
|
|
50
|
-
fi
|
|
42
|
+
spaceship::worker::init
|
|
51
43
|
|
|
52
44
|
# Start building cache from sections
|
|
53
|
-
spaceship::core::
|
|
45
|
+
spaceship::core::start
|
|
54
46
|
|
|
55
47
|
# Initiate the first render
|
|
56
48
|
spaceship::populate
|
|
@@ -59,9 +51,7 @@ prompt_spaceship_precmd() {
|
|
|
59
51
|
# A hook right before the command is started executing
|
|
60
52
|
prompt_spaceship_preexec() {
|
|
61
53
|
# Stop running prompt async jobs
|
|
62
|
-
|
|
63
|
-
async_flush_jobs "spaceship"
|
|
64
|
-
fi
|
|
54
|
+
spaceship::worker::flush
|
|
65
55
|
|
|
66
56
|
# Start measuring exec_time right before executing the command
|
|
67
57
|
spaceship_exec_time_start
|
|
@@ -69,9 +59,7 @@ prompt_spaceship_preexec() {
|
|
|
69
59
|
|
|
70
60
|
# A hook after changing the working directory
|
|
71
61
|
prompt_spaceship_chpwd() {
|
|
72
|
-
|
|
73
|
-
async_worker_eval "spaceship" 'cd' "$PWD"
|
|
74
|
-
fi
|
|
62
|
+
spaceship::worker::eval builtin cd -q $PWD
|
|
75
63
|
|
|
76
64
|
# Restart execution time recording once dir is changed
|
|
77
65
|
spaceship_exec_time_start
|
package/lib/worker.zsh
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# ------------------------------------------------------------------------------
|
|
2
|
+
# WORKER
|
|
3
|
+
# Spaceship wrapper around zsh-async
|
|
4
|
+
# ------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
# Unique array of async jobs
|
|
7
|
+
typeset -ahU SPACESHIP_JOBS=()
|
|
8
|
+
|
|
9
|
+
# Load zsh-async if not loaded yet
|
|
10
|
+
spaceship::worker::load() {
|
|
11
|
+
if ! (( ASYNC_INIT_DONE )); then
|
|
12
|
+
builtin source "$SPACESHIP_ROOT/async.zsh"
|
|
13
|
+
spaceship::precompile "$SPACESHIP_ROOT/async.zsh"
|
|
14
|
+
fi
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Lower worker priority to avoid slowing down the prompt
|
|
18
|
+
spaceship::worker::renice() {
|
|
19
|
+
if command -v renice >/dev/null; then
|
|
20
|
+
command renice +15 -p $$
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
if command -v ionice >/dev/null; then
|
|
24
|
+
command ionice -c 3 -p $$
|
|
25
|
+
fi
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# This should be called to in callback to update the job counter
|
|
29
|
+
spaceship::worker::callback() {
|
|
30
|
+
SPACESHIP_JOBS=("${(@)SPACESHIP_JOBS:#${1}}")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Start the worker and prepare the environment
|
|
34
|
+
spaceship::worker::init() {
|
|
35
|
+
if spaceship::is_prompt_async; then
|
|
36
|
+
SPACESHIP_JOBS=()
|
|
37
|
+
# restart worker
|
|
38
|
+
async_stop_worker "spaceship"
|
|
39
|
+
async_start_worker "spaceship" -n -u
|
|
40
|
+
# setopt before call register to avoid callback by async_worker_eval
|
|
41
|
+
async_worker_eval "spaceship" setopt extendedglob
|
|
42
|
+
async_worker_eval "spaceship" spaceship::worker::renice
|
|
43
|
+
async_register_callback "spaceship" spaceship::core::async_callback
|
|
44
|
+
fi
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Flush jobs for stopped worker
|
|
48
|
+
spaceship::worker::flush() {
|
|
49
|
+
if spaceship::is_prompt_async; then
|
|
50
|
+
async_flush_jobs "spaceship"
|
|
51
|
+
fi
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# Eval command inside the worker
|
|
55
|
+
spaceship::worker::eval() {
|
|
56
|
+
if spaceship::is_prompt_async; then
|
|
57
|
+
async_worker_eval "spaceship" "$@"
|
|
58
|
+
fi
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Run a job in a worker
|
|
62
|
+
spaceship::worker::run() {
|
|
63
|
+
if spaceship::is_prompt_async; then
|
|
64
|
+
SPACESHIP_JOBS+=("$1")
|
|
65
|
+
async_job "spaceship" "$@"
|
|
66
|
+
fi
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Crystal
|
|
3
|
+
#
|
|
4
|
+
# Crystal is a programming that aimes to be "fast as C, slick as Ruby."
|
|
5
|
+
# Link: https://www.crystal-lang.org
|
|
6
|
+
|
|
7
|
+
# ------------------------------------------------------------------------------
|
|
8
|
+
# Configuration
|
|
9
|
+
# ------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
SPACESHIP_CRYSTAL_SHOW="${SPACESHIP_CRYSTAL_SHOW=true}"
|
|
12
|
+
SPACESHIP_CRYSTAL_ASYNC="${SPACESHIP_CRYSTAL_ASYNC=true}"
|
|
13
|
+
SPACESHIP_CRYSTAL_PREFIX="${SPACESHIP_CRYSTAL_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
|
|
14
|
+
SPACESHIP_CRYSTAL_SUFFIX="${SPACESHIP_CRYSTAL_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
|
|
15
|
+
SPACESHIP_CRYSTAL_SYMBOL="${SPACESHIP_CRYSTAL_SYMBOL="🔮 "}"
|
|
16
|
+
SPACESHIP_CRYSTAL_COLOR="${SPACESHIP_CRYSTAL_COLOR=069}"
|
|
17
|
+
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
# Section
|
|
20
|
+
# ------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
# Show current version of Crystal
|
|
23
|
+
spaceship_crystal() {
|
|
24
|
+
[[ $SPACESHIP_CRYSTAL_SHOW == false ]] && return
|
|
25
|
+
|
|
26
|
+
# Return when crystal is not installed
|
|
27
|
+
spaceship::exists crystal || return
|
|
28
|
+
|
|
29
|
+
# If we are in a Crystal-specific project
|
|
30
|
+
local is_crystal_project="$(spaceship::upsearch shard.yml)"
|
|
31
|
+
[[ -n "$is_crystal_project" || -n *.cr(#qN^/) ]] || return
|
|
32
|
+
|
|
33
|
+
local crystal_version=$(crystal --version | awk '/Crystal*/ {print $2}')
|
|
34
|
+
|
|
35
|
+
spaceship::section \
|
|
36
|
+
--color "$SPACESHIP_CRYSTAL_COLOR" \
|
|
37
|
+
--prefix "$SPACESHIP_CRYSTAL_PREFIX" \
|
|
38
|
+
--suffix "$SPACESHIP_CRYSTAL_SUFFIX" \
|
|
39
|
+
--symbol "$SPACESHIP_CRYSTAL_SYMBOL" \
|
|
40
|
+
"v$crystal_version"
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Deno
|
|
3
|
+
#
|
|
4
|
+
# Deno is secure runtime for JavaScript and TypeScript.
|
|
5
|
+
# Link: https://deno.land/
|
|
6
|
+
|
|
7
|
+
# ------------------------------------------------------------------------------
|
|
8
|
+
# Configuration
|
|
9
|
+
# ------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
SPACESHIP_DENO_SHOW="${SPACESHIP_DENO_SHOW=true}"
|
|
12
|
+
SPACESHIP_DENO_ASYNC="${SPACESHIP_DENO_ASYNC=true}"
|
|
13
|
+
SPACESHIP_DENO_PREFIX="${SPACESHIP_DENO_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
|
|
14
|
+
SPACESHIP_DENO_SUFFIX="${SPACESHIP_DENO_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
|
|
15
|
+
SPACESHIP_DENO_SYMBOL="${SPACESHIP_DENO_SYMBOL="🦕 "}"
|
|
16
|
+
SPACESHIP_DENO_DEFAULT_VERSION="${SPACESHIP_DENO_DEFAULT_VERSION=""}"
|
|
17
|
+
SPACESHIP_DENO_COLOR="${SPACESHIP_DENO_COLOR="cyan"}"
|
|
18
|
+
|
|
19
|
+
# ------------------------------------------------------------------------------
|
|
20
|
+
# Section
|
|
21
|
+
# ------------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
# Show current version of Deno
|
|
24
|
+
spaceship_deno() {
|
|
25
|
+
[[ $SPACESHIP_DENO_SHOW == false ]] && return
|
|
26
|
+
|
|
27
|
+
# Return when deno is not installed
|
|
28
|
+
spaceship::exists deno || return
|
|
29
|
+
|
|
30
|
+
# Show Deno status only for Deno-specific folders
|
|
31
|
+
local is_deno_project="$(spaceship::upsearch deno.json deno.jsonc)"
|
|
32
|
+
[[ -n "$is_deno_project" || -n {mod,dep,main,cli}.ts(#qN^/) ]] || return
|
|
33
|
+
|
|
34
|
+
local deno_version=$(deno --version 2>/dev/null | head -1 | cut -d' ' -f2)
|
|
35
|
+
|
|
36
|
+
[[ "$deno_version" == "$SPACESHIP_DENO_DEFAULT_VERSION" ]] && return
|
|
37
|
+
|
|
38
|
+
spaceship::section \
|
|
39
|
+
--color "$SPACESHIP_DENO_COLOR" \
|
|
40
|
+
--prefix "$SPACESHIP_DENO_PREFIX" \
|
|
41
|
+
--suffix "$SPACESHIP_DENO_SUFFIX" \
|
|
42
|
+
--symbol "$SPACESHIP_DENO_SYMBOL" \
|
|
43
|
+
"v$deno_version"
|
|
44
|
+
}
|
package/spaceship.zsh
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
# Current version of Spaceship
|
|
9
9
|
# Useful for issue reporting
|
|
10
|
-
export SPACESHIP_VERSION='4.
|
|
10
|
+
export SPACESHIP_VERSION='4.5.0'
|
|
11
11
|
|
|
12
12
|
# Determination of Spaceship working directory
|
|
13
13
|
# https://git.io/vdBH7
|
|
@@ -36,7 +36,7 @@ fi
|
|
|
36
36
|
|
|
37
37
|
if [ -z "$SPACESHIP_PROMPT_ORDER" ]; then
|
|
38
38
|
SPACESHIP_PROMPT_ORDER=(
|
|
39
|
-
time # Time
|
|
39
|
+
time # Time stamps section
|
|
40
40
|
user # Username section
|
|
41
41
|
dir # Current directory section
|
|
42
42
|
host # Hostname section
|
|
@@ -45,6 +45,7 @@ if [ -z "$SPACESHIP_PROMPT_ORDER" ]; then
|
|
|
45
45
|
package # Package version
|
|
46
46
|
node # Node.js section
|
|
47
47
|
bun # Bun section
|
|
48
|
+
deno # Deno section
|
|
48
49
|
ruby # Ruby section
|
|
49
50
|
python # Python section
|
|
50
51
|
elm # Elm section
|
|
@@ -57,6 +58,7 @@ if [ -z "$SPACESHIP_PROMPT_ORDER" ]; then
|
|
|
57
58
|
haskell # Haskell Stack section
|
|
58
59
|
java # Java section
|
|
59
60
|
julia # Julia section
|
|
61
|
+
crystal # Crystal section
|
|
60
62
|
docker # Docker section
|
|
61
63
|
aws # Amazon Web Services section
|
|
62
64
|
gcloud # Google Cloud Platform section
|
|
@@ -100,6 +102,7 @@ SPACESHIP_PROMPT_DEFAULT_SUFFIX="${SPACESHIP_PROMPT_DEFAULT_SUFFIX=" "}"
|
|
|
100
102
|
SPACESHIP_LIBS=(
|
|
101
103
|
"lib/utils.zsh" # General porpuse utils
|
|
102
104
|
"lib/cache.zsh" # Cache utils
|
|
105
|
+
"lib/worker.zsh" # Async worker
|
|
103
106
|
"lib/hooks.zsh" # Zsh hooks
|
|
104
107
|
"lib/section.zsh" # Section utils
|
|
105
108
|
"lib/core.zsh" # Core functions for loading and rendering
|