Skip to content

Commit 3b1238a

Browse files
author
jedahan
committed
Switch to zsh-style functions
1 parent de360cf commit 3b1238a

21 files changed

+162
-194
lines changed

changelog.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,40 @@
33
The format is based on [Keep a Changelog](http://keepachangelog.com/)
44
and this project adheres to [Semantic Versioning](http://semver.org/).
55

6-
## Unreleased
6+
# Unreleased
7+
8+
## 3.0.0 - 2025-01-06
9+
10+
Years later, we are back. Many bugfixes and small annoyances and incompatibilities gone. A few breaking changes.
11+
12+
Removed geometry_exec_time, will re-add after a future refactor.
13+
14+
GEOMETRY_INFO now uses zsh statusline instead of being an empty command alias.
15+
16+
### Added
17+
- Add geometry_jj function for jujutsu
718
- Add GEOMETRY_TITLE and GEOMETRY_CMDTITLE as display locations
819
- Add geometry_cmd function to display currently-running command in GEOMETRY_CMDTITLE
920

21+
### Removed
22+
- Removed geometry_exec_time
23+
1024
### Fixed
25+
- Fix initial terminal RPROMPT being blank
26+
- Fix showing stale information in RPROMPT
27+
- Fix extra newline when printing GEOMETRY_INFO
1128
- Fix git functions erroring out in non-git directories (thanks @duncanbeevers!)
1229
- Git conflict counting with multiple files (thanks @gluxon!)
1330
- Fix git_status when the git directory contains spaces (thanks @tanyaionova!)
14-
- Do not print newline on enter if GEOMETRY_INFO is empty
31+
- Fix compatibility with znap (thanks @cweagans)
32+
33+
### Changed
34+
- Manually autoload functions we ship, to avoid loading user-created files
35+
- Prefix some functions with `builtin` to avoid user-defined aliases and functions
36+
37+
---
38+
39+
# Released
1540

1641
## 2.2.0 - 2020-01-13
1742

functions/geometry_docker_machine

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# geometry_docker_machine - show the current docker machine name
22

3-
geometry_docker_machine() {
4-
[[ -n $DOCKER_MACHINE_NAME ]] || return
5-
6-
ansi ${GEOMETRY_DOCKER_MACHINE_COLOR:=blue} "(${GEOMETRY_DOCKER_MACHINE_SYMBOL:="⚓"} ${DOCKER_MACHINE_NAME})"
7-
}
3+
[[ -n $DOCKER_MACHINE_NAME ]] || return
4+
ansi ${GEOMETRY_DOCKER_MACHINE_COLOR:=blue} "(${GEOMETRY_DOCKER_MACHINE_SYMBOL:="⚓"} ${DOCKER_MACHINE_NAME})"

functions/geometry_echo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# geometry_echo - simple echo for a balanced terminal
22

3-
geometry_echo() { echo -n ${GEOMETRY_ECHO:-''}; }
3+
echo -n ${GEOMETRY_ECHO:-''}

functions/geometry_exec_time

-24
This file was deleted.

functions/geometry_exitcode

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# geometry_exitcode - show the exit code of the last status
22

3-
geometry_exitcode() {
4-
(( $GEOMETRY[LAST_STATUS] )) && ansi ${GEOMETRY_EXITCODE_COLOR:-red} $GEOMETRY[LAST_STATUS] || echo ''
5-
}
3+
(( $GEOMETRY[LAST_STATUS] )) && ansi ${GEOMETRY_EXITCODE_COLOR:-red} $GEOMETRY[LAST_STATUS] || echo ''

functions/geometry_git

+18-21
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,21 @@ geometry_git_conflicts() {
8484
ansi ${GEOMETRY_GIT_COLOR_CONFLICTS_UNSOLVED:-red} "${GEOMETRY_GIT_SYMBOL_CONFLICTS_UNSOLVED:-'◈'} $count"
8585
}
8686

87-
geometry_git() {
88-
(( $+commands[git] )) || return
89-
90-
_geometry_git_guard || return
91-
92-
$(git rev-parse --is-bare-repository) \
93-
&& ansi ${GEOMETRY_GIT_COLOR_BARE:=blue} ${GEOMETRY_GIT_SYMBOL_BARE:="⬢"} \
94-
&& return
95-
96-
local git_info && git_info=(
97-
geometry_git_rebase
98-
geometry_git_remote
99-
geometry_git_branch
100-
geometry_git_conflicts
101-
geometry_git_time
102-
geometry_git_stashes
103-
geometry_git_status
104-
)
105-
106-
geometry::wrap $PWD $git_info
107-
}
87+
(( $+commands[git] )) || return
88+
_geometry_git_guard || return
89+
90+
$(git rev-parse --is-bare-repository) \
91+
&& ansi ${GEOMETRY_GIT_COLOR_BARE:=blue} ${GEOMETRY_GIT_SYMBOL_BARE:="⬢"} \
92+
&& return
93+
94+
local git_info && git_info=(
95+
geometry_git_rebase
96+
geometry_git_remote
97+
geometry_git_branch
98+
geometry_git_conflicts
99+
geometry_git_time
100+
geometry_git_stashes
101+
geometry_git_status
102+
)
103+
104+
geometry::wrap $PWD $git_info

functions/geometry_hg

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# geometry_hg - display current mercurial branch and status
22

3-
geometry_hg() {
4-
(( $+commands[hg] )) || return 1
5-
[[ -d .hg ]] || return 2
3+
(( $+commands[hg] )) || return 1
4+
[[ -d .hg ]] || return 2
65

7-
local branch="$(ansi ${GEOMETRY_HG_COLOR_BRANCH:=242} "$(hg branch 2> /dev/null)")"
6+
local branch="$(ansi ${GEOMETRY_HG_COLOR_BRANCH:=242} "$(hg branch 2> /dev/null)")"
87

9-
[[ -n "$(hg status 2> /dev/null)" ]] \
10-
&& local symbol="$(ansi ${GEOMETRY_HG_COLOR_DIRTY:=red} ${GEOMETRY_HG_SYMBOL_DIRTY:="⬡"})" \
11-
|| local symbol="$(ansi ${GEOMETRY_HG_COLOR_CLEAN:=green} ${GEOMETRY_HG_SYMBOL_CLEAN:="⬢"})"
8+
[[ -n "$(hg status 2> /dev/null)" ]] \
9+
&& local symbol="$(ansi ${GEOMETRY_HG_COLOR_DIRTY:=red} ${GEOMETRY_HG_SYMBOL_DIRTY:="⬡"})" \
10+
|| local symbol="$(ansi ${GEOMETRY_HG_COLOR_CLEAN:=green} ${GEOMETRY_HG_SYMBOL_CLEAN:="⬢"})"
1211

13-
echo -n "${branch}${GEOMETRY_HG_SYMBOL_SEPARATOR:=::}${symbol}"
14-
}
12+
echo -n "${branch}${GEOMETRY_HG_SYMBOL_SEPARATOR:=::}${symbol}"

functions/geometry_hostname

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# geometry_hostname - show user@hostname
22

3-
geometry_hostname() {
4-
local _host=${HOST:-$HOSTNAME}
5-
[[ "$_host" = "${GEOMETRY_HOSTNAME_HIDE_ON:-localhost}" ]] && return
6-
echo -n "${USER}${GEOMETRY_HOSTNAME_SEPARATOR:-@}${_host}"
7-
}
3+
local _host=${HOST:-$HOSTNAME}
4+
[[ "$_host" = "${GEOMETRY_HOSTNAME_HIDE_ON:-localhost}" ]] && return
5+
echo -n "${USER}${GEOMETRY_HOSTNAME_SEPARATOR:-@}${_host}"

functions/geometry_jj

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# geometry_jj - display current jujutsu status
22

3-
geometry_jj () {
4-
(( $+commands[jj] )) || return 1
5-
jj log --quiet --no-pager --no-graph --ignore-working-copy --revisions @ --color never --template \
6-
${GEOMETRY_JJ_TEMPLATE:-'"%F{5}" ++ change_id.shortest() ++ "%F{4}" ++ commit_id.shortest() ++ "%f% "'} \
7-
2> /dev/null
8-
}
3+
(( $+commands[jj] )) || return 1
4+
jj log --quiet --no-pager --no-graph --ignore-working-copy --revisions @ --color never --template \
5+
${GEOMETRY_JJ_TEMPLATE:-'"%F{5}" ++ change_id.shortest() ++ "%F{4}" ++ commit_id.shortest() ++ "%f% "'} \
6+
2> /dev/null

functions/geometry_jobs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# geometry_jobs - show background jobs count `⚙ 1`
22

3-
geometry_jobs() { [[ 0 -ne "$(jobs | wc -l)" ]] && ansi ${GEOMETRY_JOBS_COLOR:=blue} '%(1j.'${GEOMETRY_JOBS_SYMBOL:="⚙"}' %j.)'; }
3+
[[ 0 -ne "$(jobs | wc -l)" ]] && ansi ${GEOMETRY_JOBS_COLOR:=blue} '%(1j.'${GEOMETRY_JOBS_SYMBOL:="⚙"}' %j.)'

functions/geometry_kube

+11-13
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ geometry_kube_version() {
1919
ansi ${GEOMETRY_KUBE_VERSION_COLOR:=default} ${kube_version:=default}
2020
}
2121

22-
geometry_kube() {
23-
(( $+commands[kubectl] )) || return
22+
(( $+commands[kubectl] )) || return
2423

25-
( ${GEOMETRY_KUBE_PIN:=true} ) || return
24+
( ${GEOMETRY_KUBE_PIN:=true} ) || return
2625

27-
( ${GEOMETRY_KUBE_PIN:=false} ) || [[ -n "$KUBECONFIG" ]] || [[ -n "$(kubectl config current-context 2> /dev/null)" ]] || return
26+
( ${GEOMETRY_KUBE_PIN:=false} ) || [[ -n "$KUBECONFIG" ]] || [[ -n "$(kubectl config current-context 2> /dev/null)" ]] || return
2827

29-
local geometry_kube_details && geometry_kube_details=(
30-
$(geometry_kube_symbol)
31-
$(geometry_kube_context)
32-
$(geometry_kube_namespace)
33-
$(geometry_kube_version)
34-
)
28+
local geometry_kube_details && geometry_kube_details=(
29+
$(geometry_kube_symbol)
30+
$(geometry_kube_context)
31+
$(geometry_kube_namespace)
32+
$(geometry_kube_version)
33+
)
3534

36-
local separator=${GEOMETRY_KUBE_SEPARATOR:-"|"}
37-
echo -n ${(pj.$separator.)geometry_kube_details}
38-
}
35+
local separator=${GEOMETRY_KUBE_SEPARATOR:-"|"}
36+
echo -n ${(pj.$separator.)geometry_kube_details}

functions/geometry_newline

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# geometry_newline - add to the end of GEOMETRY_PROMPT to get a 2-line prompt!
22

3-
geometry_newline() { echo "\n\0"; }
3+
echo "\n\0"

functions/geometry_node

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# geometry_node - show node and npm/yarm version when in a node project context
22

3-
geometry_node() {
4-
(( $+commands[node] )) || return
3+
(( $+commands[node] )) || return
54

6-
test -n "$GEOMETRY_NODE_PIN" || test -f package.json || test -f yarn.lock || return 1
5+
test -n "$GEOMETRY_NODE_PIN" || test -f package.json || test -f yarn.lock || return 1
76

8-
GEOMETRY_NODE=$(ansi ${GEOMETRY_NODE_COLOR:=green} ${GEOMETRY_NODE_SYMBOL="⬡"})
7+
GEOMETRY_NODE=$(ansi ${GEOMETRY_NODE_COLOR:=green} ${GEOMETRY_NODE_SYMBOL="⬡"})
98

10-
local package_manager=npm
9+
local package_manager=npm
1110

12-
(( $+commands[yarn] )) && [[ -f yarn.lock ]] && package_manager=yarn
11+
(( $+commands[yarn] )) && [[ -f yarn.lock ]] && package_manager=yarn
1312

14-
local packager_version="$($package_manager --version 2>/dev/null)"
15-
local node_version="$(node -v 2>/dev/null)"
16-
echo -n "$GEOMETRY_NODE $node_version ($package_manager:$packager_version)"
17-
}
13+
local packager_version="$($package_manager --version 2>/dev/null)"
14+
local node_version="$(node -v 2>/dev/null)"
15+
echo -n "$GEOMETRY_NODE $node_version ($package_manager:$packager_version)"
+11-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# geometry_npm_package_version - display the current folder's npm package version from package.json (by @drager)
22

3-
geometry_npm_package_version() {
4-
[[ -f package.json ]] || return 1
5-
6-
: ${GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL:="📦"}
7-
: ${GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL_COLOR:=red}
8-
: ${GEOMETRY_NPM_PACKAGE_VERSION_COLOR:=red}
9-
10-
local npm_package_version="$(\grep version package.json | \grep --color=never -oE '[0-9]+\.[0-9]+\.[0-9]')"
11-
12-
local symbol="$(ansi $GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL_COLOR $GEOMETRY_NPM_PACKAGE_SYMBOL)"
13-
local version="$(ansi $GEOMETRY_NPM_PACKAGE_VERSION_COLOR v$npm_package_version)"
14-
echo -n $symbol $version
15-
}
3+
[[ -f package.json ]] || return 1
4+
5+
: ${GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL:="📦"}
6+
: ${GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL_COLOR:=red}
7+
: ${GEOMETRY_NPM_PACKAGE_VERSION_COLOR:=red}
8+
9+
local npm_package_version="$(\grep version package.json | \grep --color=never -oE '[0-9]+\.[0-9]+\.[0-9]')"
10+
11+
local symbol="$(ansi $GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL_COLOR $GEOMETRY_NPM_PACKAGE_SYMBOL)"
12+
local version="$(ansi $GEOMETRY_NPM_PACKAGE_VERSION_COLOR v$npm_package_version)"
13+
echo -n $symbol $version

functions/geometry_path

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# geometry_path - show the current path
22

3-
geometry_path() {
4-
local dir=${GEOMETRY_PATH_SYMBOL_HOME:-"%$GEOMETRY_PATH_TRUNCATE~"} # symbol representing the home directory
5-
( ${GEOMETRY_PATH_SHOW_BASENAME:-false} ) && dir=${PWD:t}
6-
ansi ${GEOMETRY_PATH_COLOR:-blue} $dir
7-
}
3+
# symbol representing the home directory
4+
dir=${GEOMETRY_PATH_SYMBOL_HOME:-"%$GEOMETRY_PATH_TRUNCATE~"}
5+
( ${GEOMETRY_PATH_SHOW_BASENAME:-false} ) && dir=${PWD:t}
6+
ansi ${GEOMETRY_PATH_COLOR:-blue} $dir

functions/geometry_ruby

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
# geometry_ruby - display the current ruby version, rvm version, and gemset
22

3-
geometry_ruby() {
4-
(( $+commands[ruby] )) || return
3+
(( $+commands[ruby] )) || return
54

6-
GEOMETRY_RUBY=$(ansi ${GEOMETRY_RUBY_COLOR:=default} ${GEOMETRY_RUBY_SYMBOL:="◆"})
5+
GEOMETRY_RUBY=$(ansi ${GEOMETRY_RUBY_COLOR:=default} ${GEOMETRY_RUBY_SYMBOL:="◆"})
76

8-
[[ $(ruby -v) =~ 'ruby ([0-9a-zA-Z.]+)' ]]
9-
local ruby_version=$match[1]
7+
[[ $(ruby -v) =~ 'ruby ([0-9a-zA-Z.]+)' ]]
8+
local ruby_version=$match[1]
109

11-
(( $+commands[rvm] )) && {
12-
[[ $(rvm -v) =~ 'rvm ([0-9a-zA-Z.]+)' ]]
13-
local rvm_version=$match[1]
10+
(( $+commands[rvm] )) && {
11+
[[ $(rvm -v) =~ 'rvm ([0-9a-zA-Z.]+)' ]]
12+
local rvm_version=$match[1]
1413

1514

16-
( ${GEOMETRY_RUBY_RVM_SHOW_GEMSET:=true} ) && {
17-
[[ $(rvm current) =~ 'ruby-[0-9.]+@?(.*)' ]]
18-
local gemset=${match[1]:-"default"}
19-
}
15+
( ${GEOMETRY_RUBY_RVM_SHOW_GEMSET:=true} ) && {
16+
[[ $(rvm current) =~ 'ruby-[0-9.]+@?(.*)' ]]
17+
local gemset=${match[1]:-"default"}
2018
}
21-
22-
echo -n "${(j: :):-$GEOMETRY_RUBY $ruby_version $rvm_version $gemset}"
2319
}
20+
21+
echo -n "${(j: :):-$GEOMETRY_RUBY $ruby_version $rvm_version $gemset}"

functions/geometry_rust_version

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# geometry_rust_version - display the current version of rust (by @drager)
22

3-
geometry_rust_version() {
4-
{ test -f Cargo.toml || ls -1 '*rs' 2>/dev/null; } || return 1
3+
{ test -f Cargo.toml || ls -1 '*rs' 2>/dev/null; } || return 1
54

6-
local rust_version="$(rustc --version | \grep --color=never -oE '[0-9]+\.[0-9]+\.[0-9]')"
7-
8-
ansi ${GEOMETRY_RUST_VERSION_COLOR:=red} v$rust_version
9-
}
5+
local rust_version="$(rustc --version | \grep --color=never -oE '[0-9]+\.[0-9]+\.[0-9]')"
6+
7+
ansi ${GEOMETRY_RUST_VERSION_COLOR:=red} v$rust_version

functions/geometry_rustup

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# geometry_rustup - display a symbol colored with the currently selected rustup toolchain
22

3-
geometry_rustup() {
4-
(( $+commands[rustup] )) || return
3+
(( $+commands[rustup] )) || return
54

6-
( ${GEOMETRY_RUSTUP_PIN:=false} ) || { cargo locate-project 2>/dev/null || { echo -n '' && return; } }
5+
( ${GEOMETRY_RUSTUP_PIN:=false} ) || { cargo locate-project 2>/dev/null || { echo -n '' && return; } }
76

8-
: ${GEOMETRY_RUSTUP_STABLE_COLOR:=green}
9-
: ${GEOMETRY_RUSTUP_BETA_COLOR:=yellow}
10-
: ${GEOMETRY_RUSTUP_NIGHTLY_COLOR:=red}
7+
: ${GEOMETRY_RUSTUP_STABLE_COLOR:=green}
8+
: ${GEOMETRY_RUSTUP_BETA_COLOR:=yellow}
9+
: ${GEOMETRY_RUSTUP_NIGHTLY_COLOR:=red}
1110

12-
local toolchain="$(rustup show | grep 'stable|beta|nightly' | head -n 1 | cut -d '-' -f 1 | tr -d '\n' 2> /dev/null)"
13-
local rustup_color=${(e)toolchain:+\$GEOMETRY_RUSTUP_${toolchain:u}_COLOR}
11+
local toolchain="$(rustup show | grep 'stable|beta|nightly' | head -n 1 | cut -d '-' -f 1 | tr -d '\n' 2> /dev/null)"
12+
local rustup_color=${(e)toolchain:+\$GEOMETRY_RUSTUP_${toolchain:u}_COLOR}
1413

15-
ansi $rustup_color ${GEOMETRY_RUSTUP_SYMBOL:=⚙}
16-
}
14+
ansi $rustup_color ${GEOMETRY_RUSTUP_SYMBOL:=⚙}

functions/geometry_status

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# geometry_status - show a symbol with error/success and root/non-root information
22

3-
geometry_status() {
4-
local root; [[ $UID = 0 || $EUID = 0 ]] && root=true || root=false
5-
local error; (( $GEOMETRY[LAST_STATUS] )) && error=true || error=false
3+
local root; [[ $UID = 0 || $EUID = 0 ]] && root=true || root=false
4+
local error; (( $GEOMETRY[LAST_STATUS] )) && error=true || error=false
65

7-
local color=${GEOMETRY_STATUS_COLOR:-default}
6+
local color=${GEOMETRY_STATUS_COLOR:-default}
87

9-
if ( $error );
10-
then
11-
color=${GEOMETRY_STATUS_COLOR_ERROR:-red};
12-
fi
8+
if ( $error );
9+
then
10+
color=${GEOMETRY_STATUS_COLOR_ERROR:-red};
11+
fi
1312

14-
( $root && $error ) && ansi $color ${GEOMETRY_STATUS_SYMBOL_ROOT_ERROR:=▽} && return
15-
( $root ) && ansi $color ${GEOMETRY_STATUS_SYMBOL_ROOT:-▼} && return
16-
( $error ) && ansi $color ${GEOMETRY_STATUS_SYMBOL_ERROR:-△} && return
17-
ansi $color ${GEOMETRY_STATUS_SYMBOL:-▲}
18-
}
13+
( $root && $error ) && ansi $color ${GEOMETRY_STATUS_SYMBOL_ROOT_ERROR:=▽} && return
14+
( $root ) && ansi $color ${GEOMETRY_STATUS_SYMBOL_ROOT:-▼} && return
15+
( $error ) && ansi $color ${GEOMETRY_STATUS_SYMBOL_ERROR:-△} && return
16+
ansi $color ${GEOMETRY_STATUS_SYMBOL:-▲}

0 commit comments

Comments
 (0)