agnoster / agnoster-zsh-theme

A ZSH theme designed to disclose information contextually, with a powerline aesthetic
3.98k stars 585 forks source link

Q: right side of prompt - time, exit code and history ID #125

Open replay111 opened 4 years ago

replay111 commented 4 years ago

question: is there a way to add on the right side of prompt information about time, last command exit code and last command history number?

ayozemr commented 4 years ago

I have this one https://github.com/romkatv/powerlevel10k

replay111 commented 4 years ago

Hi,

I've changed a little bit agnostic theme attached to oh-my-zsh:

prompt_agnoster_precmd() {
  RV=$?
  vcs_info
  PROMPT='%{%f%b%k%}$(prompt_agnoster_main) '
  RPROMPT="$(my_right_prompt)"
}

my_right_prompt() {
  local BATTERYLEVEL=`pmset -g batt | grep -Eo "\d+%" | cut -d% -f1`
  local BATTERYCOLOR=green

  if [ $BATTERYLEVEL -lt 90 ]; then
     BATTERYCOLOR=191
  fi
  if [ $BATTERYLEVEL -lt 70 ]; then
     BATTERYCOLOR=179
  fi
  if [ $BATTERYLEVEL -lt 50 ]; then
     BATTERYCOLOR=174
  fi
  if [ $BATTERYLEVEL -lt 30 ]; then
     BATTERYCOLOR=209
  fi
  if [ $BATTERYLEVEL -lt 15 ] ; then
     BATTERYCOLOR=001

  [[ $RV -ne 0 ]] && line="%{%F{red}%}$CROSS"
  [[ $RV -eq 0 ]] && line="%{%F{green}%}$TICK"

  local DATALONG=$(date +%Y-%m-%d\ %H:%M:%S)
  local DATASHORT=$(date +%H:%M:%S)

  $(battery_time_remaining) $BATTERYLEVEL%%]"
  line+="[$DATASHORT]%{%F{$BATTERYCOLOR}%}[$BATTERYICON $BATTERYLEVEL%%]"
  echo -n $line
}