Skip to content

Commit

Permalink
Show user@host when running in a container (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSpence authored Sep 24, 2020
1 parent b8335a6 commit 7cc22a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ prompt_pure_state_setup() {
# Show `username@host` if logged in through SSH.
[[ -n $ssh_connection ]] && username='%F{$prompt_pure_colors[user]}%n%f'"$hostname"

# Show `username@host` if inside a container.
prompt_pure_is_inside_container && username='%F{$prompt_pure_colors[user]}%n%f'"$hostname"

# Show `username@host` if root, with username in default color.
[[ $UID -eq 0 ]] && username='%F{$prompt_pure_colors[user:root]}%n%f'"$hostname"

Expand All @@ -691,6 +694,12 @@ prompt_pure_state_setup() {
)
}

# Return true if executing inside a Docker or LXC container.
prompt_pure_is_inside_container() {
([[ -r /proc/1/cgroup ]] && grep -q -E "(lxc|docker)" /proc/1/cgroup ) \
|| [[ "$container" == "lxc" ]]
}

prompt_pure_system_report() {
setopt localoptions noshwordsplit

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Most prompts are cluttered, ugly and slow. We wanted something visually pleasing
- Indicates when you have unpushed/unpulled `git` commits with up/down arrows. *(Check is done asynchronously!)*
- Prompt character turns red if the last command didn't exit with `0`.
- Command execution time will be displayed if it exceeds the set threshold.
- Username and host only displayed when in an SSH session.
- Username and host only displayed when in an SSH session or a container.
- Shows the current path in the title and the [current folder & command](screenshot-title-cmd.png) when a process is running.
- Support VI-mode indication by reverse prompt symbol (Zsh 5.3+).
- Makes an excellent starting point for your own custom prompt.
Expand Down

0 comments on commit 7cc22a4

Please sign in to comment.