Commit 1d26e2ab authored by Marc Cornellà's avatar Marc Cornellà
Browse files

trapd00r: convert perl script to zsh

Used color encodings from
https://metacpan.org/source/WOLDRICH/Term-ExtendedColor-0.224/lib/Term/ExtendedColor.pm
parent abca62ad
...@@ -36,54 +36,46 @@ local c11=$(printf "\e[38;5;208m\e[1m") ...@@ -36,54 +36,46 @@ local c11=$(printf "\e[38;5;208m\e[1m")
local c12=$(printf "\e[38;5;142m\e[1m") local c12=$(printf "\e[38;5;142m\e[1m")
local c13=$(printf "\e[38;5;196m\e[1m") local c13=$(printf "\e[38;5;196m\e[1m")
local zsh_path_pl='
zsh_path() {
use strict; local -A yellow
use Term::ExtendedColor "fg"; yellow=(
1 '%F{228}' 2 '%F{222}' 3 '%F{192}' 4 '%F{186}'
chomp(my $pwd = `pwd`); 5 '%F{227}' 6 '%F{221}' 7 '%F{191}' 8 '%F{185}'
9 '%F{226}' 10 '%F{220}' 11 '%F{190}' 12 '%F{184}'
my @chars = split//, $pwd; 13 '%F{214}' 14 '%F{178}' 15 '%F{208}' 16 '%F{172}'
17 '%F{202}' 18 '%F{166}'
my $i = 1; )
for(@chars) { local c i=1
if($_ eq "/") { for c (${(s::)PWD}); do
if(defined($ENV{DISPLAY})) { if [[ $c = "/" ]]; then
if($i == 1) { if [[ $i -eq 1 ]]; then
print fg("green28", fg("bold", " /")); if [[ -n "$DISPLAY" ]]; then
$i++; print -Pn '%F{065}%B /%b%f'
next; else
} print -Pn '\e[31;1m /%f'
} fi
else { (( i++ ))
if($i == 1) { continue
print "\e[31;1m /\e[0m"; fi
$i++;
next; if [[ -n "$DISPLAY" ]]; then
} print -Pn "${yellow[$i]:-%f} » %f"
} else
print -Pn "%F{yellow} > %f"
if(defined($ENV{DISPLAY})) { fi
print fg("yellow$i", " » "); (( i += 6 ))
$i += 6 else
} if [[ -n "$DISPLAY" ]]; then
else { print -Pn "%F{065}$c%f"
print "\e[33m > \e[0m"; else
$i += 6; print -Pn "%F{blue}$c%f"
} fi
} fi
else { done
if(defined($ENV{DISPLAY})) {
print fg("green28", $_);
}
else {
print "\e[34m$_\e[0m";
}
}
} }
'
# We don't want to use the extended colorset in the TTY / VC. # We don't want to use the extended colorset in the TTY / VC.
if [ "$TERM" = "linux" ]; then if [ "$TERM" = "linux" ]; then
...@@ -116,24 +108,24 @@ add-zsh-hook precmd prompt_jnrowe_precmd ...@@ -116,24 +108,24 @@ add-zsh-hook precmd prompt_jnrowe_precmd
prompt_jnrowe_precmd () { prompt_jnrowe_precmd () {
vcs_info vcs_info
if [ "${vcs_info_msg_0_}" = "" ]; then if [ "${vcs_info_msg_0_}" = "" ]; then
dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(echo $zsh_path_pl | perl)%} %{$c0%}(%{$c5%}%?%{$c0%})" dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
PROMPT='%{$fg_bold[green]%}%p%{$reset_color%}${vcs_info_msg_0_}${dir_status} ${ret_status}%{$reset_color%} PROMPT='%{$fg_bold[green]%}%p%{$reset_color%}${vcs_info_msg_0_}${dir_status} ${ret_status}%{$reset_color%}
> ' > '
# modified, to be committed # modified, to be committed
elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then
dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(echo $zsh_path_pl | perl)%} %{$c0%}(%{$c5%}%?%{$c0%})" dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
PROMPT='${vcs_info_msg_0_}%{$30%} %{$bg_bold[red]%}%{$fg_bold[cyan]%}C%{$fg_bold[black]%}OMMIT%{$reset_color%} PROMPT='${vcs_info_msg_0_}%{$30%} %{$bg_bold[red]%}%{$fg_bold[cyan]%}C%{$fg_bold[black]%}OMMIT%{$reset_color%}
%{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%} %{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%}
> ' > '
elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then
dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(echo $zsh_path_pl | perl)%} %{$c0%}(%{$c5%}%?%{$c0%})" dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
PROMPT='${vcs_info_msg_0_}%{$bg_bold[red]%}%{$fg_bold[blue]%}D%{$fg_bold[black]%}IRTY%{$reset_color%} PROMPT='${vcs_info_msg_0_}%{$bg_bold[red]%}%{$fg_bold[blue]%}D%{$fg_bold[black]%}IRTY%{$reset_color%}
%{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%} %{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%}
%{$c13%}>%{$c0%} ' %{$c13%}>%{$c0%} '
else else
dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(echo $zsh_path_pl | perl)%} %{$c0%}(%{$c5%}%?%{$c0%})" dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
PROMPT='${vcs_info_msg_0_} PROMPT='${vcs_info_msg_0_}
%{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%} %{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%}
> ' > '
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment