diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-10-04 22:57:19 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-10-04 22:57:19 +0000 |
commit | d3170c8ee6eb6aa6050d6531536e5e9fba278b57 (patch) | |
tree | 4be666df9d3dcce75a68560c44f40b6efe79c24d /Misc/bash2zshprompt | |
parent | 298c35419d8da664ba22f9daa26758798da390d4 (diff) | |
download | zsh-d3170c8ee6eb6aa6050d6531536e5e9fba278b57.tar.gz zsh-d3170c8ee6eb6aa6050d6531536e5e9fba278b57.tar.xz zsh-d3170c8ee6eb6aa6050d6531536e5e9fba278b57.zip |
Initial revision
Diffstat (limited to 'Misc/bash2zshprompt')
-rw-r--r-- | Misc/bash2zshprompt | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/Misc/bash2zshprompt b/Misc/bash2zshprompt new file mode 100644 index 000000000..aa0472ed1 --- /dev/null +++ b/Misc/bash2zshprompt @@ -0,0 +1,100 @@ +#!/usr/bin/perl -w +# +# exceedingly ugly hack to convert bashprompt themes to zshprompt themes +# (bashprompt is at http://bash.current.nu/) +# +# Adam Spiers <adam@spiers.net> + +use strict; + +my @colours = qw/grey red green yellow blue magenta cyan white/; + +my @codes = (); +my %bold; +my $out = ''; + +print "# Converted to zsh prompt theme by bash2zshprompt, written by <adam\@spiers.net>\n"; + +my $seen_fn = 0; +my $seen_fn_end = 0; +while (<>) { + # Ugh + if (! $seen_fn) { + s/^\s*function (\w+) {\s*$/prompt_$1_setup () {\n/ and $seen_fn = $1; + } + # UGH + elsif (! $seen_fn_end && $seen_fn) { + s/^\s*/ /; + s/^\s*}\s*$/\n precmd () { }\n preexec () { }\n}\n/ and $seen_fn_end++; + } + + s/\\\[/%{/g; + s/\\\]/%}/g; + + s/\\033/\\e/g; + s/\\e\[([0-9;]+)m/split_codes($1)/eg; + s/\\e\[((\d?)(\d))m/color()/eg; + + s/(?<!\\)\\u/%n/g; + s/(?<!\\)\\h/%m/g; + s/(?<!\\)\\t/%t/g; + s/(?<!\\)\\d/%D{%a %b %d}/g; + s/(?<!\\)\\?\$\(date\s+\+([^)]+)\)/%D{$1}/g; + s/(?<!\\)\\!/%!/g; + s/(?<!\\)\\#/%!/g; # hmmm + s/(?<!\\)\\n/\$prompt_newline/g; + s/(?<!\\)\\s/\$SHELL/g; + s/(?<!\\)\\w/%~/g; + s/(?<!\\)\\W/%1~/g; + s/(?<!\\)\\\$(?!\()/%\#/g; + + s/(?<!\\)\\0?(\d{3})/push @codes, $1; "\$char_$1"/eg; + + s/%}%{//g; + + $out .= $_; +} + +# Must be a better way of doing this +print <<EOF if @codes; + +for code in @codes; do + local varname=char_\$code + : \${(P)varname=\$(echo -n "\\\\0\$code")} +done + +EOF + +print $out; + +print qq!\nprompt_${seen_fn}_setup "\$@"\n! if $seen_fn; + +exit 0; + +sub color { + my @p = ($1, $2, $3); + + my $fgbg = (($p[1] eq '3') ? 'fg' : + ($p[1] eq '4') ? 'bg' : + '???'); + + $bold{$fgbg} ||= ''; + + if ($p[0] =~ /^0?0$/) { + $bold{$fgbg} = ''; + return '$reset_color'; + } + + if ($p[0] =~ /^0?1$/) { + $bold{$fgbg} = 'bold_'; + return '$bold_color'; + } + + return '$' . + "${fgbg}_$bold{$fgbg}" . + $colours[$p[2]]; +} + +sub split_codes { + join '', (map { "\\e\[${_}m" } (split m!;!, $_[0])); +} |