LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2021, 08:50 AM   #1
072aar
LQ Newbie
 
Registered: Aug 2021
Posts: 2

Rep: Reputation: Disabled
Lightbulb multiline bar prompt in zsh


hello. I am trying to construct a bar prompt in zsh; that is I want a left prompt right prompt a solid bar between them and a newline which will have the current directory. On the left prompt I will have user@hostname and on the right prompt will be date/time. When I run the code everything shows up correctly except the newline and the newline prompt. Here is what I have so far:
Code:
autoload -U promptinit
promptinit

autoload -Uz compinit
compinit
_comp_options+=(globdots)


setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT
setopt PROMPT_SUBST
setopt PROMPT_BANG
setopt PROMPT_PERCENT

pipe_color='%{%F{#ffffff}%}'
pipe_bg_color='%{%K{#414a4c}%}'
username_color='%{%F{#000000}%}'
username_bg_color='%{%K{#c0c5ce}%}'
at_color='%{%F{#ffffff}%}'
at_bg_color='%{%K{#414a4c}%}'
machine_color='%{%F{#ffffff}%}'
machine_bg_color='%{%K{#005b96}%}'
date_color='%{%F{#000000}%}'
date_bg_color='%{%K{#ffa700}%}'
time_color='%{%F{#ffa700}%}'
time_bg_color='%{%K{#000000}%}'
bar_color='%{%F{#00330b}%}'
bar_bg_color='%{%K{#00330b%}'
reset_color='%{%f%k%}'
USERNAME=$(id -un) 
UNLENGTH=${#USERNAME}
HOST=$(hostname)
HNLENGTH=${#HOST}
PIPES_AT_BRACKETS=16
DATE=$(date +"[%F]")
DTLENGTH=${#DATE}
TIME=$(date +"[%H:%M:%S]")
TMLENGTH=${#TIME}
COLS=$(tput cols)
TOTAL_COLUMNS=${COLS}
USED_COLUMNS=$((${UNLENGTH} + ${HNLENGTH} + ${PIPES_AT_BRACKETS} + ${DTLENGTH} + ${TMLENGTH}))
BAR_SPACES=$((${TOTAL_COLUMNS} - ${USED_COLUMNS}))
NEWLINE=$'\n'

function setPS1 {
function printBar {
print -v NEWLINE $'\U000A'
print -v PSNewline '%{#ffffff}%K{#000000}|%f%k%F{#ffffff}%K{#36802d}[%~]%f%k%F{#ffffff}%K{#000000}|%f%k'
print -v BAR "seq -s ' ' 0 ${BAR_SPACES} | tr -d '[:digit:]'"
}
}

function precmd {
setPS1
}

# shopt -s checkwinsize; (:;:)
COLUMNS=
resize &>/dev/null

print -v PROMPT '${pipe_color}${pipe_bg_color}|${reset_color}${username_color}${username_bg_color}[%n]${reset_color}${pipe_color}${pipe_bg_color}|${reset_color}${at_color}${at_bg_color}@${reset_color}${pipe_color}${pipe_bg_color}|${reset_color}${machine_color}${machine_bg_color}[%M]${reset_color}${pipe_color}${pipe_bg_color}|${reset_color}${bar_color}${bar_bg_color}${BAR}${PSNewline}'

print -v RPROMPT '${pipe_color}${pipe_bg_color}|${reset_color}${date_color}${date_bg_color}${DATE}${reset_color}${pipe_color}${pipe_bg_color}|${reset_color}${time_color}${time_bg_color}${TIME}${reset_color}${pipe_color}${pipe_bg_color}|'
I've tried placing the "\n" for the newline prompt everywhere I could think of but it never displays right. appreciate your input.
 
Old 09-04-2021, 11:02 AM   #2
072aar
LQ Newbie
 
Registered: Aug 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile Explanation of scripting string..

Hi I was wondering what this string does--I found it while trying to learn about building a zsh prompt. The FULL line of code is like so:
Code:
PS1='%K{green}$left${(l,COLUMNS-${#${(%)left}},)${${:-$branch | $mode}//[%]/%%}}%k$ '
I understand PS1 and the %K and $left but the part I'm needing help with is:

Code:
${(l,COLUMNS-${#${(%)left}},)${${:-$branch | $mode}//[%]/%%}}%k$ '
Or, what do I need to read in the zsh manual to understand this line of code. I'm trying to build a prompt like this--I don't need the 'insert' mode; I want user@host for leftprompt, date/time as right prompt and the pwd on a newline. I need a solid bar between left and right prompt:
Click image for larger version

Name:	barprompt0.png
Views:	11
Size:	11.7 KB
ID:	37126
Any input greatly appreciated for this noob.
 
Old 09-05-2021, 01:13 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,715
Blog Entries: 11

Rep: Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being merged with your previous thread on this topic.
 
  


Reply

Tags
prompt, zsh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] zsh - extend zsh completion blueray Linux - Newbie 1 10-17-2020 02:44 AM
LXer: Excellent Utilities: Liquid Prompt – adaptive prompt for Bash & Zsh LXer Syndicated Linux News 0 09-23-2019 08:42 AM
ZSH -- Apple switching BASH => ZSH, what do you think? LQParsons Linux - Newbie 2 06-06-2019 10:01 AM
LXer: How to Setup ZSH and Oh-my-zsh on Linux LXer Syndicated Linux News 0 11-02-2017 12:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration