diff --git a/changelog.md b/changelog.md index bcab27d..ac0707f 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Add GEOMETRY_TITLE and GEOMETRY_CMDTITLE as display locations +- Add geometry_cmd function to display currently-running command in GEOMETRY_CMDTITLE ### Fixed - Fix git functions erroring out in non-git directories (thanks @duncanbeevers!) diff --git a/geometry.zsh b/geometry.zsh index 42352fd..19730ff 100644 --- a/geometry.zsh +++ b/geometry.zsh @@ -9,12 +9,16 @@ typeset -gA GEOMETRY; GEOMETRY[ROOT]=${0:A:h} (($+GEOMETRY_PROMPT)) || GEOMETRY_PROMPT=(geometry_echo geometry_status geometry_path) (($+GEOMETRY_RPROMPT)) || GEOMETRY_RPROMPT=(geometry_exec_time geometry_git geometry_hg geometry_echo) (($+GEOMETRY_INFO)) || GEOMETRY_INFO=() +(($+GEOMETRY_TITLE)) || GEOMETRY_TITLE=(geometry_path) +(($+GEOMETRY_CMDTITLE)) || GEOMETRY_CMDTITLE=(geometry_cmd geometry_hostname) autoload -U add-zsh-hook function { local fun; for fun ("${GEOMETRY[ROOT]}"/functions/*) . $fun } (( $+functions[ansi] )) || ansi() { (($# - 2)) || echo -n "%F{$1}$2%f"; } +(( $+functions[deansi] )) || deansi() { (($# - 1)) || echo -n "$(echo "$1" | sed s/$(echo "\033")\\\[\[0-9\]\\\{1,2\\\}m//g)"; } +(( $+functions[geometry_cmd])) || geometry_cmd() { echo $GEOMETRY_LAST_CMD } # Takes number of seconds and formats it for humans # from https://github.com/sindresorhus/pretty-time-zsh @@ -59,13 +63,25 @@ geometry::hostcolor() { echo ${colors[${index}]} } -# set title to COMMAND @ CURRENT_DIRECTORY -geometry::set_title() { print -n "\e]0;${2} @ ${PWD##*/}\a"; } -add-zsh-hook preexec geometry::set_title +# set cmd title (while command is running) +geometry::set_cmdtitle() { + # Make command title available for optional consumption by geometry_cmd + GEOMETRY_LAST_CMD=$2 + local ansiCmdTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_CMDTITLE)) + local cmdTitle=$(deansi "$ansiCmdTitle") -# clear title after command ends -geometry::clear_title() { print -n '\e]0;%~\a'; } -add-zsh-hook precmd geometry::clear_title + echo -ne "\e]1;$cmdTitle\a" +} +add-zsh-hook preexec geometry::set_cmdtitle + +# set ordinary title (after command has completed) +geometry::set_title() { + local ansiTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_TITLE)) + local title=$(deansi "$ansiTitle") + + echo -ne "\e]1;$title\a" +} +add-zsh-hook precmd geometry::set_title # join outputs of functions - pwd first geometry::wrap() { diff --git a/readme.md b/readme.md index 1cb740b..0e04262 100644 --- a/readme.md +++ b/readme.md @@ -43,17 +43,27 @@ tool | add to `.zshrc` ![showing prompt customization with new function](./images/screenshots/functions.png) -Geometry has very little architecture. Three environment variables define what is shown on the left, right, and on enter - `GEOMETRY_PROMPT`, `GEOMETRY_RPROMPT`, and `GEOMETRY_INFO`. +Geometry displays output in several places. The output displayed in each location is determined by the plugins configured for that location. +These are the supported locations, along with the environment variable used to configure each one. -Most of these functions only show up if it makes sense to (for example, `geometry_git` only shows up if in a git repository). +Variable Name | Text display location +---------------------|------------------------------------------------------- +GEOMETRY_PROMPT | Text shown to the left of the cursor +GEOMETRY_RPROMPT | Text shown at the right edge of the terminal +GEOMETRY_INFO | Text shown after pressing enter with no input +GEOMETRY_TITLE | Text shown in the terminal title +GEOMETRY_CMDTITLE | Text shown in the terminal title when a command is run -To customize the prompt, just add any function to any of the `GEOMETRY_PROMPT`, `GEOMETRY_RPROMPT`, or `GEOMETRY_INFO` variables: +To customize the prompt, add any function to the list of functions for the desired display location: ```sh GEOMETRY_PROMPT=(geometry_status geometry_path) # redefine left prompt GEOMETRY_RPROMPT+=(geometry_exec_time pwd) # append exec_time and pwd right prompt +GEOMETRY_TITLE=(geometry_node) ``` +Most of these functions only show up if it makes sense to (for example, `geometry_git` only shows up if in a git repository). + Please check out and share third-party functions on our [functions wiki page][] For more details on how to create a function, check out [our contribution guide][]