Fixes for OMP prompts and for default PATH

This commit is contained in:
Andrea Mistrali 2021-12-17 09:14:01 +01:00
parent 0ae9cfdb9e
commit 51bd0516d6
No known key found for this signature in database
GPG Key ID: 6FB0A77F6D5DA9B2
8 changed files with 185 additions and 13 deletions

View File

@ -47,13 +47,13 @@ blocks:
- type: executiontime - type: executiontime
style: plain style: plain
foreground: lightBlue foreground: darkGray
properties: properties:
always_enabled: false always_enabled: false
postfix: "" postfix: ""
prefix: "\uF017 " prefix: "\uF017 "
style: austin style: austin
threshold: 3000 threshold: 30000
- type: prompt - type: prompt
alignment: right alignment: right
@ -63,9 +63,9 @@ blocks:
style: plain style: plain
foreground: yellow foreground: yellow
properties: properties:
postfix: " " postfix: ""
# prefix: # prefix: " "
prefix: "\uF270" prefix: "\u2601 "
template: '{{if .Profile}}{{.Profile}}{{end}}' template: '{{if .Profile}}{{.Profile}}{{end}}'
- type: kubectl - type: kubectl
@ -74,7 +74,7 @@ blocks:
properties: properties:
parse_kubeconfig: true parse_kubeconfig: true
postfix: "" postfix: ""
prefix: "" prefix: " "
template: '{{if eq "on" .Env.KUBE_PS1_ENABLED}}ﴱ {{.Context}}/{{if .Namespace}}{{.Namespace}}{{else}}default{{end}}{{end}}' template: '{{if eq "on" .Env.KUBE_PS1_ENABLED}}ﴱ {{.Context}}/{{if .Namespace}}{{.Namespace}}{{else}}default{{end}}{{end}}'
# - type: command # - type: command

115
omp/realpure.omp.yaml Normal file
View File

@ -0,0 +1,115 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
console_title: true
console_title_style: template
console_title_template: '{{if .Env.SSH_CONNECTION}} {{ .Host }} {{end}}{{.Path}}'
final_space: false
blocks:
- type: prompt
alignment: left
newline: false
segments:
- type: session
style: plain
foreground: yellow
properties:
postfix: ""
prefix: ""
template: '{{if .SSHSession}}@{{ .ComputerName }} {{end}}'
- type: root
style: plain
foreground: yellow
properties:
postfix: ""
prefix: ""
root_icon: "\u26A1"
# root_icon: "# "
- type: path
style: plain
foreground: lightBlue
properties:
prefix: ""
style: full
- type: git
style: plain
foreground: yellow
properties:
branch_ahead_icon: <#88C0D0>⇡</>
branch_behind_icon: <#88C0D0>⇣</>
branch_icon: ""
display_status: true
fetch_status: true
prefix: ""
template: '{{ .HEAD }}{{.BranchStatus}}{{ if .Working.Changed }}<#FF0000>* {{ .Working.String }}</>{{ end }}'
- type: executiontime
style: plain
foreground: yellow
properties:
always_enabled: false
postfix: ""
prefix: " "
style: austin
threshold: 30000
- type: prompt
alignment: right
segments:
- type: aws
style: plain
foreground: "#ffA000"
properties:
postfix: ""
# prefix: " "
prefix: " "
template: '{{if .Profile}}{{.Profile}}{{end}}'
- type: kubectl
style: plain
foreground: lightBlue
properties:
parse_kubeconfig: true
postfix: ""
prefix: " "
template: '{{if eq "on" .Env.KUBE_PS1_ENABLED}}|{{.Context}}/{{if .Namespace}}{{.Namespace}}{{else}}default{{end}}|{{end}}'
# - type: command
# style: plain
# foreground: white
# prefix: ""
# postfix: ""
# properties:
# shell: /bin/sh
# # command: "ifconfig utun2 > /dev/null 2>&1 && echo '\uF023' || echo ''"
# command: "ifconfig utun2 > /dev/null 2>&1 && echo '\u2713' || echo '\u2717'"
- type: prompt
alignment: left
newline: true
segments:
- type: python
style: plain
foreground: darkGray
properties:
display_version: false
postfix: ""
prefix: ""
- type: exit
style: plain
foreground: lightYellow
foreground_templates:
- '{{ if gt .Code 0 }}#FF0000{{ end }}'
properties:
always_enabled: true
prefix: ""
# template:
template: "\u276F"

View File

@ -2,7 +2,6 @@
# Variables # Variables
## Vars used always ## Vars used always
PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin:$HOME/bin:."
MIBS=all MIBS=all
LOGD=/var/log LOGD=/var/log

View File

@ -1,5 +1,5 @@
fpath=($0:h/prompts $fpath) fpath=($0:h/prompts $fpath)
# fpath+=$0:h/prompts/mypure fpath+=$0:h/prompts/mypure
# fpath+=$0:h/prompts/pure # fpath+=$0:h/prompts/pure
autoload -U promptinit;promptinit autoload -U promptinit;promptinit

View File

@ -5,7 +5,7 @@
# Setup brew # Setup brew
# We need it here to fix the PATH # We need it here to fix the PATH
# so we can setup pyenv and other stuff # so we can setup pyenv and other stuff
#
for prefix in /usr/local /opt/homebrew; do for prefix in /usr/local /opt/homebrew; do
brew=$(whence $prefix/bin/brew) brew=$(whence $prefix/bin/brew)
if [ $brew ]; then if [ $brew ]; then

View File

@ -21,8 +21,6 @@ if [ $profile ]; then # We got a profile pattern, look for a match
print -P "$FX[bold]activating profile $FG[075]$match$FX[reset]" print -P "$FX[bold]activating profile $FG[075]$match$FX[reset]"
export AWS_DEFAULT_PROFILE=$match export AWS_DEFAULT_PROFILE=$match
export AWS_PROFILE=$match export AWS_PROFILE=$match
export AWS_DEFAULT_REGION=$(grep -A1 $match ~/.aws/config|grep region|cut -d" " -f3)
export AWS_REGION=${AWS_DEFAULT_REGION}
return return
else else
print -P "$FX[bold]$FG[009]no match for $profile$FX[reset]" print -P "$FX[bold]$FG[009]no match for $profile$FX[reset]"
@ -30,7 +28,7 @@ if [ $profile ]; then # We got a profile pattern, look for a match
fi fi
elif [ $AWS_PROFILE ]; then # no profile passed, clean up current one, logout elif [ $AWS_PROFILE ]; then # no profile passed, clean up current one, logout
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_DEFAULT_REGION AWS_REGION unset AWS_DEFAULT_PROFILE AWS_PROFILE
print -P "$FX[bold]profile cleared$FX[reset]." print -P "$FX[bold]profile cleared$FX[reset]."
return return
fi fi

View File

@ -7,7 +7,60 @@ cd $1
gitdir=$(git rev-parse --git-dir 2> /dev/null) || return 0 gitdir=$(git rev-parse --git-dir 2> /dev/null) || return 0
last_fetch=$(zstat +mtime $gitdir/FETCH_HEAD 2> /dev/null || echo 0) last_fetch=$(zstat +mtime $gitdir/FETCH_HEAD 2> /dev/null || echo 0)
let "diff = $(strftime %s) - $last_fetch" let "diff = $(strftime %s) - $last_fetch"
[ $diff -gt ${GIT_FETCH_INTERVAL:-30} ] && git fetch --all -p if [ $diff -gt ${GIT_FETCH_INTERVAL:-30} ]; then
setopt localoptions noshwordsplit
# Sets `GIT_TERMINAL_PROMPT=0` to disable authentication prompt for Git fetch (Git 2.3+).
export GIT_TERMINAL_PROMPT=0
# Set SSH `BachMode` to disable all interactive SSH password prompting.
export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-"ssh"} -o BatchMode=yes"
local ref
ref=$(command git symbolic-ref -q HEAD)
local -a remote
remote=($(command git for-each-ref --format='%(upstream:remotename) %(refname)' $ref))
if [[ -z $remote[1] ]]; then
# No remote specified for this branch, skip fetch.
return 97
fi
# Default return code, which indicates Git fetch failure.
local fail_code=99
# Guard against all forms of password prompts. By setting the shell into
# MONITOR mode we can notice when a child process prompts for user input
# because it will be suspended. Since we are inside an async worker, we
# have no way of transmitting the password and the only option is to
# kill it. If we don't do it this way, the process will corrupt with the
# async worker.
setopt localtraps monitor
# Make sure local HUP trap is unset to allow for signal propagation when
# the async worker is flushed.
trap - HUP
trap '
# Unset trap to prevent infinite loop
trap - CHLD
if [[ $jobstates = suspended* ]]; then
# Set fail code to password prompt and kill the fetch.
fail_code=98
kill %%
fi
' CHLD
# Only fetch information for the current branch and avoid
# fetching tags or submodules to speed up the process.
command git -c gc.auto=0 fetch \
--quiet \
--no-tags \
--recurse-submodules=no \
$remote &>/dev/null &
wait $! || return $fail_code
unsetopt monitor
fi
return 0 return 0

7
zshrc
View File

@ -11,6 +11,7 @@
# at the bottom of ~/.zshrc add `zprof >! zsh_profile` to save # at the bottom of ~/.zshrc add `zprof >! zsh_profile` to save
# profiling data at startup # profiling data at startup
# zmodload zsh/zprof # zmodload zsh/zprof
# Determine zsh conf file position. On Debian/Ubuntu is /etc/zsh, on other should be /etc # Determine zsh conf file position. On Debian/Ubuntu is /etc/zsh, on other should be /etc
# #
[ -d /etc/zsh ] && BASE="/etc/zsh" || BASE="/etc" [ -d /etc/zsh ] && BASE="/etc/zsh" || BASE="/etc"
@ -38,6 +39,9 @@ function loadRC {
done done
} }
# Default PATH
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
local KERNEL=`uname -s` local KERNEL=`uname -s`
local LIBRARY=${BASE}/zsh.d local LIBRARY=${BASE}/zsh.d
local KERNLIB=${LIBRARY}/${KERNEL} local KERNLIB=${LIBRARY}/${KERNEL}
@ -45,6 +49,9 @@ local KERNLIB=${LIBRARY}/${KERNEL}
loadRC ${KERNLIB} loadRC ${KERNLIB}
loadRC ${LIBRARY} loadRC ${LIBRARY}
# Add home bin to PATH
PATH="$PATH:$HOME/bin"
# Add local customization file # Add local customization file
if [ -w $LIBRARY ]; then if [ -w $LIBRARY ]; then
[ -f $LIBRARY/99-local.zsh ] || echo "# Local customizations" > $LIBRARY/99-local.zsh [ -f $LIBRARY/99-local.zsh ] || echo "# Local customizations" > $LIBRARY/99-local.zsh