chris-marsh / pureline Goto Github PK
View Code? Open in Web Editor NEWA Pure Bash Powerline PS1 Command Prompt
License: MIT License
A Pure Bash Powerline PS1 Command Prompt
License: MIT License
An addendum to the initial concern: This only seems to occur within tmux
using Ctrl+L to reset the terminal resets the cursor location back one space
using Ctrl+U to clear the terminal line up to the PS1 does the same thing
it would appear that the git module ignores the colors given in the config file and always uses MyOrange
Hello! I'm using your pureline code to beautify my prompts. Thanks for your work!
I've installed the current latest git version, but I still have an issue on a Ubuntu 20.04 system. I'm using xfce-term4 and I ssh from a Ubuntu 20.04 system. I'm using the same config line on both systems. On my local system line wrapping works correctly. Over ssh, with pureline enabled, it doesn't work correctly for the first line!
Here is my config: https://paste.ubuntu.com/p/fDsKPmq68B/
adrianp ~ $ echo 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
adrianp ~ $
adrianp ~ $ ssh frost-vpn
... Banner omitted for brevity ...
Last login: Thu Mar 18 10:28:29 2021 from 192.168.1.11
adrianp 💻 frost ~ $
34567890 💻 frost ~ $ echo 1234567890 1234567890 1234567890 12
1234567890 1234567890 1234567890 1234567890
Any suggestions what I should be looking for?
Thanks!
2 days ago, merging PR #66 "Allowing TMUX pane titles to persist" reintroduced this bug that I fixed in merged PR #72 "Fixes when inherited PROMPT_COMMAND is not empty" :
[FIX-1]
function 'pureline_pre' now returns the saved error code of the last executed command.
=> Does not break an inherited PROMPT_COMMAND that requires that value.
Please merge #83 "Don't set the GUI window title if PL_TITLEBAR is empty" to cleanly solve that issue.
Hi
If a config file is provided as an argument and the path to the config file has a space in it, the sourcing of it fails.
Line 385 in 3184589
regards,
Jinesh
pureline
is now always showing a single job running in the background. I've traced the issue to the fact that I have PROMPT_COMMAND="cat $XDG_CACHE_HOME/wal/sequences"
in my bashrc
. The issue isn't specific to that file; cat
itself seems to be the problem.
Need to improve the performance of the git segment.
git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
number_stash=$(git stash list 2>/dev/null
number_behind_ahead=$(git rev-list --count --left-right '@{upstream}...HEAD')
number_staged=$(git diff --staged --name-only --diff-filter=AM)
number_conflicts=$(git diff --name-only --diff-filter=U)
number_modified=$(git diff --name-only --diff-filter=M)
number_untracked=$(git ls-files --other --exclude-standard)
git status --porcelain # to determine dirty status
8 calls to git (plus wc
and tr
for those calls). Most of this could be reduced to a single call to git status ---porcelain --branch
and parsing the result.
This SO answer explains why OSX (and others) always output a set number of spaces from wc
. As a result, git_module on OSX is almost unusable as-is, as the line contains many unnecessary spaces.
Proposal:
Pipe the output of every wc
command to sed 's/^ *//'
in order to ensure spaces are trimmed.
It would be nice if the user module shows the $username@$host as red when logged in as root instead of green.
See patch - just two files in segments/. Hg support is pretty dumb for now, tmux support uses tmux display -p
so it can expand to pretty much anything you want.
diff --git a/segments/hg_segment b/segments/hg_segment
new file mode 100644
index 0000000..6377b59
--- /dev/null
+++ b/segments/hg_segment
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+# hg segment
+
+# Set default symbols if not already defined in config
+# Defaults should be standard symbols.
+[[ -z ${PL_SYMBOLS[hg_branch]} ]] && PL_SYMBOLS[hg_branch]="╬"
+
+# -----------------------------------------------------------------------------
+# append to prompt: hgbranch with indicators for;
+# number of; modified files, staged files and conflicts
+# arg: $1 background color
+# arg: $2 foreground color
+# option variables;
+# PL_HG_UNTRACKED: true/false
+function hg_segment {
+ which hg >/dev/null 2>&1 || return; ## return if no hg
+
+ local hg_branch="$(hg branch 2>/dev/null)"
+
+ [[ -z $hg_branch ]] && return; ## return early if not a branch/no info
+
+ local bg_color="$1"
+ local fg_color="$2"
+ local content="${PL_SYMBOLS[hg_branch]} $hg_branch"
+
+ if [[ $PL_HG_UNTRACKED == true ]]; then
+ local number_untracked="$(hg status -u -T ".\n" | wc -l | tr -d '[:space:]')"
+ if (( number_untracked != 0 )); then
+ content+=" ${PL_SYMBOLS[soft_separator]} ${PL_SYMBOLS[hg_untracked]}$number_untracked"
+ fi
+ fi
+
+ if [[ -n "$(hg status 2>/dev/null)" ]]; then
+ if [[ -v PL_HG_DIRTY_FG ]]; then
+ fg_color="$PL_HG_DIRTY_FG"
+ fi
+ if [[ -v PL_HG_DIRTY_BG ]]; then
+ bg_color="$PL_HG_DIRTY_BG"
+ fi
+ fi
+
+ PS1+="$(segment_end "$fg_color" "$bg_color")"
+ PS1+="$(segment_content "$fg_color" "$bg_color" " $content ")"
+ __last_color="$bg_color"
+}
+
diff --git a/segments/tmux_segment b/segments/tmux_segment
new file mode 100644
index 0000000..c8518df
--- /dev/null
+++ b/segments/tmux_segment
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+#
+# tmux_segment
+#
+
+# Set default symbols if not already defined in config.
+# Defaults should be standard symbols.
+
+[[ -z ${PL_SYMBOLS[tmux_session]} ]] && PL_SYMBOLS[tmux_session]='♆'
+[[ -z ${PL_SYMBOLS[tmux_window]} ]] && PL_SYMBOLS[tmux_window]='▢'
+# -----------------------------------------------------------------------------
+# append to prompt: tmux session name
+# arg: $1 background color
+# arg: $2 foreground color
+# option variables;
+# PL_TMUX_WINDOW: true/false, append window name
+
+function tmux_session_segment {
+ [[ ! -v TMUX ]] && return; ## return if $TMUX not set
+ which tmux >/dev/null 2>&1 || return; ## return if no 'tmux'
+
+ local bg_color="$1"
+ local fg_color="$2"
+ local content="${PL_SYMBOLS[tmux_session]} #{session_name}"
+
+ if [[ $PL_TMUX_WINDOW ]]; then
+ content+=" ${PL_SYMBOLS[tmux_window]} #{window_name}"
+ fi
+
+ content="$(tmux display -p "$content")"
+
+ PS1+="$(segment_end "$fg_color" "$bg_color")"
+ PS1+="$(segment_content "$fg_color" "$bg_color" " $content ")"
+ __last_color="$bg_color"
+}
+
+
When the command exists but kubernetes has no context currently configured, kubectl config current-context
prints error: current-context is not set
into the stderr.
It's annoying and can be bypassed by disabling the Kubernetes segment temporarily HOWEVER I think it may be worth fixing here:
https://github.com/chris-marsh/pureline/blob/main/segments/kubernetes_segment#L12
and changing it for:
local context=$(kubectl config current-context 2>/dev/null)
to silence the stderr (because you have the exit code and stdout will be empty when not set, so it's superfluous.)
Hi there,
I am having problems getting this going on a Pi, this is the error I am getting
-bash: PROMPT_COMMAND: line 0: syntax error near unexpected token `;'
-bash: PROMPT_COMMAND: line 0: `pureline_pre; [[ -w '/tmp/dietpi-process.pid' ]] && rm -f /tmp/dietpi-process.pid &> /dev/null && echo -ne '\r\e[J'; ; pureline_ps1;'
It is odd because it works fine on Pop OS (bash version 5.1.16) and Debian 11 (bash version 5.1.4).
If you want me to test any code changes then I am happy to do so, I tried to debug the problem myself but I could not get it working.
Many thanks
Jason
When I ssh to a macOS machine which has pureline configured, I get the following error message after every single command:
-bash: ip: command not found
This doesn't seem to affect anything as far as I can notice. The workaround is to install ip
on OS X as described here:
brew install iproute2mac
I'm not expecting a fix, but wanted to at least share the workaround where everyone encountering the problem might look for it first.
Bash complains about a test comparison inside path_module with incorrect operator introduced in commit 1045000d00b03041878e9b4c47653d19f593f52d
Printing the $3
value when inside path_module
shows that this variable holds a boolean value instead of an integer one. Don't know if this has to be that way though.
Reverting the changes of said commit fixes bash complaints about the correct use of the operator inside the test.
Bash version:
GNU bash, version 4.4.19(1)-release (x86_64-unknown-linux-gnu)
I'd gladly provide more information if needed.
EDIT: Strangely, I have not been able to reproduce this on a friend's machine. I fear that this might not be a pureline bug.
Hello,
I'm using the latest git pureline version, with this config: https://paste.ubuntu.com/p/cntRQbNmmX/
I have a weird behavior that can be visually seen in this video: https://youtu.be/U4UlqufYGAg
Any ideas where to look for clues?
My terminal is xfce4-term, on a Ubuntu 20.04 system.
Hi, i've been sitting here for the last HALF A FUCKING HOUR, trying to add a fucking \n before your command prompt.
I'VE TRIED EVERYTHING, but nothing seems to work. Right now my terminal has the same utility of Windows troubleshooter
Please HELP
Hello, I am having an issue with the pureline package that I recently installed. I followed the documentation and moved the pureline directory to .config/terminal/pureline and the .pureline.conf file to the same directory. However, when I try to run pureline, I am getting an error that states:
-bash: battery_segment: command not found -bash: ssh_segment: command not found -bash: screen_session_segment: command not found -bash: virtual_env_segment: command not found -bash: conda_env_segment: command not found -bash: aws_profile_segment: command not found -bash: kubernetes_segment: command not found -bash: git_segment: command not found -bash: duration_segment: command not found
I am new to terminal and would appreciate any help in resolving this issue.
Is there any hints / howto on how to install this for all users?
I would get that the source should exist in /etc/profile.d/something
Then install under /usr/local? or /opt?
Given iterm2, iterm2 shell integration, and the following included in my pureline configuration
function iterm2_mark_module {
if [ -n "$__last_color" ]; then
PS1+="$(section_end $__last_color 'Default')"
fi
PS1+="\[$(iterm2_prompt_mark)\]"
unset __last_color
}
function newline_module {
if [ -n "$__last_color" ]; then
PS1+="$(section_end $__last_color 'Default')"
fi
PS1+="\n\[$(iterm2_prompt_mark)\]"
unset __last_color
}
# All modules are enabled. Uncomment/comment to enable/disable a module
declare -a PL_MODULES=(
# Module Background Foreground
'time_module MyLightGrey Black'
# 'battery_module MyBlue Black'
# 'user_module MyLime Black'
'ssh_module MyYellow Black'
'virtual_env_module MyBlue Black'
'path_module MyBlue Black'
'read_only_module MyRed White'
'background_jobs_module MyPurple White'
'git_module MyGreen Black'
'return_code_module MyRed White'
'newline_module'
# 'iterm2_mark_module'
'prompt_module MyDarkGrey White'
)
This configuration puts the prompt mark on the newline as desired with the replaced newline_module
. But if I comment out my override and enable iterm2_mark_module
in PL_MODULES
, the prompt mark doesn't move to the newline.
But why?
Under macOS duration_segment
fails with
-bash: (1638285455N: value too great for base (error token is "1638285455N")
This is because macOS's native date
doesn't support %N
. I tried installing coreutils
from brew
, but that installs it as gdate
by default. At this point, there's 2 workarounds that I could think of:
replace date
with gdate
in duration_segment
(which I ended up using, suggested by brew
) prepend PATH
with /usr/local/opt/coreutils/libexec/gnubin
to make the binaries installed by coreutils
have precedence over macOS native ones
Not sure what a proper fix would be, just leaving this here for others running into it.
I don't know yet how to make a pull request.
However, I just recognized that the battery module throws up path not found errors for BAT1 because of a typo in the file pureline/pureline in line 274:
batt_dir=$batt_dir1""
should read:
batt_dir=$batt_dir"1"
I fail to understand how the SSH module is supposed to work.
If I SSH into another machine, I simply see the plain shell prompt of that machine - without any of the fancy pureline modifications. What am I missing?
Similarly, the root module seems to do nothing. As soon as I issue SU, the shell reverts to the standard prompt.
Am I supposed to additionally install pureline on the servers I SSH into and for the root account itself respectively?
Sorry for sounding dumb. I'm familiar with bash, but never played around much with command line prompt customization.
Hello !
First of all, nice work for this light customization of the bash prompt!
Could you integrate the work done here?
https://github.com/jichu4n/bash-command-timer
Thanks!
Cheers,
Raphaël
If $PL_ERASE_LINE=true
as it does by default, multiline commands break when recalled from history. As soon as you add or remove a character from the first line of the command, the entire line will disappear from view.
I use Pureline on Linux and WSL shells all the time but I recently tried to deploy it on an OSX box I ssh to sometimes and it's completely broken. :(
If it helps, my default shell is Bash (version 3.2.57), running on Darwin 20.3.0 (aka Big Sur), using the latest "main" branch:
alan@hitchcock:~$ source $HOME/repos/pureline/pureline
-bash: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
\e]2;'\u@\h: \w' alan@hitchcock ↔ ~ ↔
I guess it's probably because the Bash bundled with OSX is very old, maybe:
alan@hitchcock:~$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
Copyright (C) 2007 Free Software Foundation, Inc.
(My WSL Ubuntu environment where Pureline works perfectly has Bash 4.2 copyright 2011, for comparison.)
I was getting the square box with the SSH module. I had to update PL_SYMBOLS[ssh]
in my local .pureline from ef 84 89 20
to f0 9d 94 96
.
See tail of attached .pureline
String 30 in /pureline/segments/git_segment give subj.
Reason: cyrillic locale. Job status "Done" naming as "Завершен".
Fix: add "local LC_MESSAGES=C" in "background_jobs_segment" function.
How do I configure a segment (like time, battery) to get aligned to the right side of terminal?
README install instructions say to do:
$ cd ~
$ git clone https://github.com/chris-marsh/pureline.git
$ cp pureline/example-config.conf ~/.pureline.conf
But the file example-config.conf
is no longer there. I later understood there's example configs under the /configs
subdirectory.
It would be nice if the README was edited to give correct instructions and also explain how the various example configs provided are different.
PROMPT_COMMAND=pureline_ps1
Setting the PROMPT_COMMAND
to the result of pureline_ps1
doesn't work for gnome-terminal
I think it would be useful to have the prompt show the shell level.
This is probably more useful when you messing about with things like PureLine dev :) I'm constantly sourcing pureline or starting new bash sessions to test stuff. Working my way back with Ctrl-D is tricky to know when your at ground zero.
Prompt segment could be
|$> bash
|2$> bash
|3$> bash
|4$> ctrl-d
|2$> ctrl-d
|$>
The default prompt_module
still shows the dollar sign when root which is not the standard behavior.
Example:
22:14 furquan@debian-home ~ $ su
Password:
22:16 root@debian-home /home/furquan $
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.