Last active
July 30, 2022 15:16
-
-
Save juliennonin/e1157f76e8add2a093bab13107b18a75 to your computer and use it in GitHub Desktop.
[Linux][config] Configuration for custom PS1 (different behavior for git repo, and Python environments) and tab title in gnome-terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# >>> custom prompt PS1 >>> | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export GIT_PS1_SHOWUNTRACKEDFILES=1 | |
export GIT_PS1_SHOWUPSTREAM=auto | |
TRIANGLE_SYM=$'\ue0b0' | |
function prompt_func() { | |
# IMPORTANT: Non-printable sequences should be enclosed in \[ and \] | |
if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then # inside a git repo | |
gitsubdir=$(basename $(git rev-parse --show-toplevel))/$(git rev-parse --show-prefix) | |
PS1_NO_TITLE='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[33m\]$(__git_ps1 "(%s)")\[\033[00m\] \[\033[01;34m\]${gitsubdir%/}\[\033[00;96;01m\]\$ \[\033[00m\]' | |
TITLE="${gitsubdir%/}" | |
TITLE="$(echo -e '\uf121') ${gitsubdir%/}" | |
else # not a git repo | |
PS1_NO_TITLE='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;96;01m\]\$ \[\033[00m\]' | |
TITLE="\w" | |
fi | |
if [[ -n "$VIRTUAL_ENV" ]]; then # inside a poetry environment | |
pyversion=$(echo "$VIRTUAL_ENV" | grep -o -E --color=never '[0-9]\.[0-9]{1,2}$') | |
if [[ -z "$pyversion" ]]; then | |
pyversion="env" | |
fi | |
PS1_NO_TITLE="\[\033[40;1m\]${pyversion}\[\033[0;30m\]${TRIANGLE_SYM}\[\033[0m\]${PS1_NO_TITLE}" | |
fi | |
if [[ -n "$CONDA_PROMPT_MODIFIER" ]]; then # inside a conda environment | |
CONDA_ENV=$(echo $CONDA_PROMPT_MODIFIER | tr -d '()') | |
# echo "Hello${CONDA_ENV}" | |
PS1_NO_TITLE="\[\033[100;1m\]${CONDA_ENV}\[\033[0;90m\]${TRIANGLE_SYM}\[\033[0m\]${PS1_NO_TITLE}" | |
fi | |
if [[ -n "$TAB_TITLE" ]]; then | |
TITLE=$TAB_TITLE | |
fi | |
ESCAPED_TITLE="\[\033]2;${TITLE}\007\]" # https://unix.stackexchange.com/a/566383/521267, https://askubuntu.com/a/252233 | |
PS1="${PS1_NO_TITLE}${ESCAPED_TITLE}" | |
export PS1 | |
} | |
PROMPT_COMMAND=prompt_func | |
# <<< custom prompt PS1 <<< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start=57344 | |
end=63743 | |
nb_per_row=10 | |
undefined_codes=( | |
57453 57545 57547 57555 57948 57858 57960 57986 57992 58305 58350 58351 58376 58408 | |
58410 58411 58413 58417 58421 58422 58476 58477 58515 58630 58669 58717 61341 61342 | |
61441 61442 61443 61471 61472 61503 61519 61535 61551 61567 61583 61599 61615 61647 | |
61663 61679 61711 61718 61719 61727 61759 61791 61835 61935 61951 62063 62079 62095 | |
62111 62127 62143 62159 62175 | |
) | |
interesting_codes=() | |
for i in {57344..57399} {57402..57402} {57452..57455} {57483..57488} {57502..57506} \ | |
{57512..57514} {57520..57556} {57847..57953} {57955..57991} {57999..58001} \ | |
{58125..58140} {58253..58253} {58269..58269} {58275..58275} {58281..58283} \ | |
{58295..58312} {58320..58320} {58336..58355} {58368..58369} {58375..58378} \ | |
{58395..58398} {58405..58462} {58470..58494} {58507..58564} {58627..58631} \ | |
{58653..58675} {58696..58719} {60182..60182} {58736..58741} {58744..58748} \ | |
{58756..58759} {58765..58768} {58771..58775} {58789..58789} {58992..58992} \ | |
{59005..59005} {59008..59043} {60224..60224} {60928..60939} {61184..61209} \ | |
{61328..61343} {61375..61420} {61434..61618} {61632..61742} {61750..61774} \ | |
{61787..61806} {61815..61815} {61820..61822} {61827..61844} {61931..61936} \ | |
{61946..61959} {62062..62176}; do | |
if [[ ! " ${undefined_codes[@]} " =~ " ${i} " ]]; then | |
interesting_codes+=($i) | |
fi | |
done | |
# nb_elmts=$((end - start + 1)) | |
nb_elmts=${#interesting_codes[@]} | |
nb_per_col=$(((nb_elmts - 1) / nb_per_row)) | |
for i in $(eval echo "{0..$((nb_per_col))}"); do | |
for j in $(eval echo "{0..$((nb_per_row - 1))}"); do | |
index=$((i + (nb_per_col + 1) * j)) | |
# code_dec=$((start + i + (nb_per_col + 1) * j)) | |
code_dec=${interesting_codes[index]} | |
code_hex=$(printf '%x\n' $code_dec) | |
echo -e -n "$code_hex \u$code_hex " | |
done | |
echo | |
done | |
# f293: Bluetooth +(f294) | |
# f295: Percent | |
# f296: Gitlab | |
# f299: Leaf | |
# f2ac: Snap +(f2ab, f2ad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment