Compare commits

..

13 Commits

Author SHA1 Message Date
Nicole O'Connor
2def06fb51 comment out git unrecognized branch warning 2024-07-19 10:43:00 -07:00
Nicole O'Connor
bc14813bbb fix updates checking for md5sum (instead of cmp) before comparing zshrc for updates 2024-07-02 19:03:13 -07:00
Nicole O'Connor
96c7934a83 fix prompt builder overriding mobile prompts 2024-07-02 18:58:53 -07:00
e29862ff82 prompt builders: reset color between prompt functions 2023-08-15 12:09:31 -07:00
479805fe2a git: reset color between commit hash and branch name 2023-08-15 12:05:25 -07:00
35f517070b git: add support for tags, fix remote support, show commit hash next to checkout name 2023-08-08 13:59:59 -07:00
03c525d890 git module; adds rprompt string and auto-inits git-lfs if needed 2023-07-20 14:13:27 -07:00
798ced71aa overhaul prompt management; make it easier to add/remove things to {,r}prompt over time 2023-06-30 17:05:18 -07:00
ed5afe0300 clear rprompt from zshrc-stub to make a little more obvious when the prompt stuff isn't working right 2023-06-30 17:04:40 -07:00
45e90a1baa zshrc.preload actually, so zeesh can see conda if it exists 2023-06-30 16:23:45 -07:00
ba91da045c add support for conda; i now support two dev frameworky things so lets mention this in the readme too 2023-06-30 16:18:38 -07:00
9c7014bf32 zsh evidently has a built in $COLUMNS var! who knew 2023-04-04 13:07:32 -07:00
f085638cf7 add .zshrc.local support 2023-04-04 12:50:14 -07:00
10 changed files with 124 additions and 20 deletions

View File

@@ -5,4 +5,5 @@
* Provides a unique syntax for running ssh sessions. You can simply type `command@target-host --args` to run a one shot command on target-host (or `@target-host` to open a full ssh session)
* Customizes the prompt according to developer's personal preferences (framework for customization coming soon!)
* Automatically updates itself, and is capable of installing itself with just a stub zshrc
* Support for some developer environment tools, such as OPAM and conda
* And more, as needed!

38
base/prompt.zsh Normal file
View File

@@ -0,0 +1,38 @@
typeset -ag prompt_functions
typeset -ag rprompt_functions
function prompt_builder () {
result=""
for prompt_func in $prompt_functions; do
result="${result}$($prompt_func)%{$reset_color%} "
done
# prompt will always end with "% " (or "# " if we're somehow root)
result="${result}%#%{$reset_color%} "
print "${result}"
}
function rprompt_builder () {
result=""
for rprompt_func in $rprompt_functions; do
result="$($rprompt_func)%{$reset_color%} ${result}"
done
result="${result}%{$reset_color%}"
print "${result}"
}
if [[ $cols -lt 80 ]]; then
if [[ $(uname -o) == "Android" ]]; then
hostemoji="📞"
else
hostemoji="🖥"
fi
PROMPT="👤%{$fg_bold[white]%}@${hostemoji} %~ %# %{$reset_color%}"
else
PROMPT='$(prompt_builder)'
RPROMPT='$(rprompt_builder)'
fi
TMOUT=60
TRAPALRM () {
zle reset-prompt
}

View File

@@ -10,7 +10,7 @@ function zeesh_update () {
_zshrc_updates_pending=0
if type md5sum &> /dev/null; then
if type cmp &> /dev/null; then
cmp -s ~/.zshrc ~/.local/share/zeesh/zshrc-stub
if [[ $? -eq 1 ]]; then
cp ~/.local/share/zeesh/zshrc-stub ~/.zshrc

View File

@@ -1,4 +1,7 @@
cols=$(stty -a | grep -Po '(?<=columns )\d+' | tr -d "\n")
#cols=$(stty -a | grep -Po '(?<=columns )\d+' | tr -d "\n")
cols=$COLUMNS
setopt prompt_subst
function ticker_message () {
if [[ $_zeeshdev_ticker_newlines == 0 ]]; then

19
modules/base_prompt.zsh Normal file
View File

@@ -0,0 +1,19 @@
# PROMPT="%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~ %# %{$reset_color%}"
# RPROMPT="%(?..%{$fg[red]%}%? )$RPROMPT"
function prompt_userathost () {
print "%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~"
}
prompt_functions+=prompt_userathost
function rprompt_clock () {
print "%{$fg_bold[black]%}%T"
}
function rprompt_retval () {
print "%(?..%{$fg[red]%}%?)"
}
rprompt_functions+=rprompt_clock
rprompt_functions+=rprompt_retval

17
modules/conda.zsh Normal file
View File

@@ -0,0 +1,17 @@
# Note: location of conda can be unpredictable; user is expected to
# run `conda init zsh` as normal then move resulting .zshrc
# modifications to .zshrc.preload
# recommended settings for .condarc:
# auto_assign_base: false
# changeps1: false
function conda_prompt() {
if [[ -v CONDA_DEFAULT_ENV && "$CONDA_DEFAULT_ENV" != "base" ]]; then
print "%{$fg[cyan]%}$CONDA_DEFAULT_ENV"
fi
}
if (( ${+commands[conda]} )); then
rprompt_functions+=conda_prompt
fi

36
modules/git.zsh Normal file
View File

@@ -0,0 +1,36 @@
(( $+commands[git] )) || return
if (( $+commands[git-lfs] )); then
# ensures git-lfs is functional if installed
git config --get filter.lfs.process &> /dev/null || git lfs install
fi
function git_prompt() {
git rev-parse --is-inside-work-tree &> /dev/null
__git_prompt__is_git_dir=$?
if [[ $__git_prompt__is_git_dir -eq 0 ]]; then
commithash=$(git log --pretty=format:"%h" -n 1)
fullbranchname=$(git name-rev --name-only ${commithash})
branchtype=$(echo ${fullbranchname} | cut -d"/" -f1)
if [[ "${branchtype}" == "refs" ]]; then
branchname=$(echo ${fullbranchname} | cut -d"/" -f3)
elif [[ "${branchtype}" == "remotes" ]]; then
branchname=$(echo ${fullbranchname} | cut -d"/" -f2-)
elif [[ "${branchtype}" == "tags" ]]; then
branchname=$(echo ${fullbranchname} | cut -d"/" -f2)
elif [[ "${branchtype}" == "${fullbranchname}" ]]; then
# git did it for us
branchname=${fullbranchname}
else
branchname=${fullbranchname}
# output a warning to stderr, convenience for maintenance
#echo "warning: unrecognized branch type ${branchtype}" >&2
fi
print "%{$fg_bold[yellow]%}${branchname} %{$reset_color%}%{$fg[yellow]%}${commithash}"
fi
}
rprompt_functions+=git_prompt

View File

@@ -3,23 +3,8 @@ source ~/.local/share/zeesh/base/zeesh.zsh
ticker_message "zeesh: bootstrap"
if [[ $cols -lt 80 ]]; then
if [[ $(uname -o) == "Android" ]]; then
hostemoji="📞"
else
hostemoji="🖥"
fi
PROMPT="👤%{$fg_bold[white]%}@${hostemoji} %~ %# %{$reset_color%}"
else
PROMPT="%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~ %# %{$reset_color%}"
RPROMPT="%(?..%{$fg[red]%}%? )$RPROMPT"
fi
TMOUT=60
TRAPALRM () {
zle reset-prompt
}
source ~/.local/share/zeesh/base/precmd.zsh
source ~/.local/share/zeesh/base/prompt.zsh
source ~/.local/share/zeesh/base/updates.zsh
# TODO: handle whether or not to load given modules]

View File

@@ -1,9 +1,12 @@
# vim: ft=zsh :
# Hint: If you're looking to add things to zshrc, make a new file called .zshrc.local and
# put your changes there to avoid it getting clobbered by zeesh updates.
autoload -U colors && colors
PROMPT="%{$fg[cyan]%}%n%{$fg[white]%}@%{$fg[magenta]%}%m %{$fg[white]%}%~ %# "
RPROMPT="%{$fg_bold[black]%}%T%{$reset_color%}"
RPROMPT=""
_zeesh_fresh_install=0
@@ -23,4 +26,6 @@ fpath=(
~/.local/share/zeesh/plugins
"${fpath[@]}"
)
[[ -f ~/.zshrc.preload ]] && source ~/.zshrc.preload
source ~/.local/share/zeesh/zeesh.zsh
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local