Skip to content

Commit

Permalink
More about yash
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Aug 23, 2022
1 parent 15430cb commit c70bf88
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 54 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2017-2021 Alexandros Kozak
Copyright 2017-2022 Alexandros Kozak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Polyglot Prompt

The **Polyglot Prompt** is a dynamic prompt for `zsh`, `bash`, `ksh93`, `mksh`, `pdksh`, `dash`, and `busybox ash` that uses basic ASCII symbols (and color, when possible) to show:
The **Polyglot Prompt** is a dynamic prompt for `zsh`, `bash`, `ksh93`, `mksh`, `pdksh`, `dash`, `yash`, and `busybox ash` that uses basic ASCII symbols (and color, when possible) to show:

* the username
* whether a session is local or remote over SSH
Expand Down
68 changes: 16 additions & 52 deletions polyglot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Polyglot Prompt
#
# A dynamic color Git prompt for zsh, bash, ksh93, mksh, pdksh, dash, and
# A dynamic color Git prompt for zsh, bash, ksh93, mksh, pdksh, dash, yash, and
# busybox ash
#
#
Expand All @@ -30,7 +30,7 @@
# ~/.../bar/bat/quux
#
#
# Copyright 2017-2021 Alexandros Kozak
# Copyright 2017-2022 Alexandros Kozak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -327,17 +327,8 @@ _polyglot_basename() {
# Tests to see if the current shell is busybox ash
###########################################################
_polyglot_is_busybox() {
case $(_polyglot_basename "${0#-}") in
ash|sh)
if command -v readlink > /dev/null 2>&1; then
case $(exec 2> /dev/null; readlink /proc/$$/exe) in
*/busybox) return 0 ;;
*) return 1 ;;
esac
else
return 1
fi
;;
case $(help 2> /dev/null) in
'Built-in commands:'*) return 0 ;;
*) return 1 ;;
esac
}
Expand Down Expand Up @@ -727,51 +718,24 @@ elif _polyglot_is_pdksh || [ "${0#-}" = 'dash' ] || _polyglot_is_busybox ||
PS1=$PS1'$(_polyglot_branch_status $POLYGLOT_KSH_BANG)'
PS1=$PS1$(print "$POLYGLOT_NP\033[0m$POLYGLOT_NP")
PS1=$PS1' \$ '

elif _polyglot_is_yash && _polyglot_has_colors; then
PS1='\[\e[01;31m\]$(_polyglot_exit_status $?)\[\e[0m\]'
PS1=$PS1'$(_polyglot_venv)'
PS1=$PS1'\[\e[01;32m\]${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\[\e[0m\] '
if ! _polyglot_is_superuser; then
PS1=$PS1'\[\e[01;32m\]${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\[\e[0m\] '
else
PS1=$PS1'\[\e[7m\]${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\[\e[0m\] '
fi
PS1=$PS1'\[\e[01;34m\]$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")\[\e[0m\]'
PS1=$PS1'\[\e[33m\]$(_polyglot_branch_status $POLYGLOT_KSH_BANG)\[\e[0m\] \$ '
elif ! _polyglot_is_superuser; then
PS1='$(_polyglot_exit_status $?)$(_polyglot_venv)${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING $(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")$(_polyglot_branch_status $POLYGLOT_KSH_BANG) \$ '
else # Superuser

##########################################################
# Tests to see if the terminal is the DragonFly BSD system
# console, which displays color in pdksh badly.
##########################################################
_polyglot_is_dragonfly_console() {
case ${POLYGLOT_UNAME:=$(uname -s)} in
DragonFly)
case $(who am i) in
*ttyv*) return 0 ;;
*) return 1 ;;
esac
;;
*) return 1 ;;
esac
}

PS1=
_polyglot_is_pdksh && ! _polyglot_is_dragonfly_console && PS1=$(print "$POLYGLOT_NP\r")
PS1=$PS1'$(_polyglot_exit_status $?)'
if _polyglot_is_pdksh && ! _polyglot_is_dragonfly_console; then
case $POLYGLOT_UNAME in
NetBSD|OpenBSD) PS1="$PS1$(print "$POLYGLOT_NP")" ;;
esac
else
PS1='$(_polyglot_exit_status $?)$(_polyglot_venv)${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING $(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")$(_polyglot_branch_status $POLYGLOT_KSH_BANG) '
if ! _polyglot_is_superuser; then
PS1=$PS1'$ '
else
PS1=$PS1'# '
fi
PS1=$PS1'$(_polyglot_venv)'
# shellcheck disable=SC2025
! _polyglot_is_dragonfly_console && [ "${0#-}" != 'dash' ] && PS1="$PS1\033[7m"
_polyglot_is_pdksh && ! _polyglot_is_dragonfly_console && PS1=$PS1$(print "$POLYGLOT_NP")
PS1=$PS1'${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING'
_polyglot_is_pdksh && ! _polyglot_is_dragonfly_console && PS1=$PS1$(print "$POLYGLOT_NP")
# shellcheck disable=SC2025
! _polyglot_is_dragonfly_console && [ "${0#-}" != 'dash' ] && PS1="$PS1\033[0m"
_polyglot_is_pdksh && ! _polyglot_is_dragonfly_console && PS1=$PS1$(print "$POLYGLOT_NP")
PS1=$PS1' $(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")$(_polyglot_branch_status $POLYGLOT_KSH_BANG) # '
fi
else
printf '%s\n' 'Polyglot Prompt does not support your shell.' >&2
Expand Down

0 comments on commit c70bf88

Please sign in to comment.