.rcrc (5788B)
1 # Fuck GNU 2 if (~ `$nl{grep --version >[2=1]} *GNU*) 3 __prompt_gnu_binary = 'a' 4 5 fn __prompt_tput { 6 # Use \001 and \002 to tell readline 7 # wether a character is visible or not 8 printf '\001%s\002' `''{tput $*} 9 } 10 11 fn __prompt_exit_colour { 12 if (~ $1 0) { 13 __prompt_tput setaf 15 14 } else if (~ $1 sig*) { 15 __prompt_tput setaf 8 16 } else { 17 __prompt_tput setaf 10 18 } 19 } 20 21 fn __prompt_cleanup { 22 for (f in $__prompt_tmp) { 23 rm -f $f 24 } 25 __prompt_tmp = () 26 tput sgr0 27 } 28 29 fn sigexit { 30 __prompt_cleanup 31 for (f in $manconfs) { 32 rm -f $f 33 } 34 } 35 36 # Backend prompt function 37 fn __prompt { 38 __prompt_exitcodes = $status 39 __prompt_gitoutput = 0 40 __prompt_tmp = (/tmp/$pid.prompt.tmp $__prompt_tmp) 41 42 # exit codes 43 # rc produces a list if there is a pipeline 44 if (~ $__prompt_exitcodes(2) ()) { 45 # only one 46 __prompt_exit_colour $__prompt_exitcodes(1) 47 printf '%s ' $__prompt_exitcodes(1) | sed 's/^sig//' 48 } else { 49 __prompt_tput setaf 3 50 printf '[' 51 __prompt_print_bar = 0 52 for (__prompt_exitcode in $__prompt_exitcodes) { 53 if (~ $__prompt_print_bar 1) { 54 __prompt_tput setaf 3 55 printf '|' 56 } else { 57 __prompt_print_bar = 1 58 } 59 __prompt_exit_colour $__prompt_exitcode 60 printf '%s' $__prompt_exitcode | sed 's/^sig//' 61 } 62 __prompt_tput setaf 3 63 printf '] ' 64 } 65 66 # username 67 __prompt_tput setaf 5 68 printf '%s ' `{whoami} 69 70 if (!~ $hide_git 1) { 71 # branch 72 __prompt_tput setaf 3 73 __prompt_branch = `{git branch >[2]/dev/null | 74 grep '^*' | 75 awk '{print $2 "|"}'} 76 if (!~ $__prompt_branch ()) { 77 printf '%s' $__prompt_branch 78 __prompt_gitoutput = 1 79 } 80 81 # unstaged changes 82 git diff >[2]/dev/null > $__prompt_tmp(1) 83 __prompt_diffstatus = $bqstatus 84 if (head -n 1 < $__prompt_tmp(1) | grep '^.' >/dev/null) { 85 __prompt_tput setaf 8 86 printf '%s+' `{cat $__prompt_tmp(1) | 87 grep '-E'^$__prompt_gnu_binary '^(\+\+\+|---)' | 88 sed -E 's~^[^a]*a/|^[^b]*b/~~' | 89 grep -v /dev/null | 90 uniq | 91 wc -l | 92 tr -d '\n'} 93 __prompt_gitoutput = 1 94 } else if (~ $bqstatus 0) { 95 __prompt_tput setaf 15 96 printf '=' 97 __prompt_gitoutput = 1 98 } 99 100 # unpushed commits 101 git log '--pretty=format:commit %h%d' >[2]/dev/null > $__prompt_tmp(1) 102 if (!~ `$nl{head -n 1 < $__prompt_tmp(1)} */*) { 103 __prompt_tput setaf 14 104 < $__prompt_tmp(1) awk ' 105 BEGIN {c = 0; exitcode = 1} 106 /^commit/ { 107 if ($0 ~ /\//) { 108 printf("%d^", c) 109 exitcode = 0 110 exit(0) 111 } else c += 1 112 } 113 END { exit(exitcode) }' && __prompt_gitoutput = 1 114 } 115 } 116 117 if (~ $__prompt_gitoutput 1) { 118 printf ' ' 119 } 120 121 # dir 122 __prompt_tput setaf 7 123 printf '%s' `{pwd | sed 's~' ^ $home ^ '~\~~'} 124 125 # end 126 printf '$ ' 127 __prompt_cleanup 128 } 129 130 # Frontend prompt function 131 fn prompt { 132 __prompt_content = `''{__prompt} 133 __prompt_indent = `$nl{printf '%s' $__prompt_content | 134 awk '{gsub(/\001[^\002]*\002/, ""); print}' | 135 sed 's/[^ ]/ /g;s/$/ /g'} 136 prompt = ($__prompt_content $__prompt_indent) 137 138 # missing newline 139 # https://www.vidarholen.net/contents/blog/?p=878 140 __prompt_tput setaf 14 141 printf '%%' 142 tr '\0' ' ' < /dev/zero | head -c `{tput cols} | sed 's/.//' 143 printf '\r' 144 145 # set X11 title 146 printf '\033]0;rc (%s)\007' `{pwd | sed 's~' ^ $home ^ '~\~~'} 147 } 148 149 # Aliases 150 fn g { git $* } 151 fn vsplit { vim -O $* } 152 if (~ `{uname} 'Linux') { 153 fn ls { 154 if (flag i) { 155 builtin ls -FC --color $* 156 } else { 157 # rc exports all functions, 158 # so we need to act normal 159 # when not interactive. 160 builtin ls $* 161 } 162 } 163 } 164 fn v { nvim $* } 165 fn xi { doas xbps-install $*} 166 fn xr { doas xbps-remove $*} 167 fn xq { doas xbps-query $*} 168 fn ytdl { youtube-dl --add-metadata -ic $* } 169 fn ytdla { youtube-dl --add-metadata -xic $* } 170 fn tmux { builtin tmux -f $home/.config/tmux/config $* } 171 fn sloccount { 172 mkdir -p $home/.local/sloccount 173 builtin sloccount --datadir $home/.local/sloccount $* 174 } 175 fn camerasync { 176 rsync -azP /mnt/DCIM/* $home/general/images/byme 177 } 178 fn wtf { 179 if (flag i) { 180 builtin wtf -o $* 181 } else { 182 builtin wtf $* 183 } 184 } 185 fn w3m { 186 # Symlink $home/.config/w3m -> $home/.config/.w3m 187 home = $home/.config { builtin w3m $* } 188 } 189 fn _man { 190 conf = '/tmp/'^$pid^'.man.conf' program = $1 { 191 sed -E 's~HOME~'^$home^'~g' < $home/.config/man.conf > $conf 192 manconfs = ($manconfs $conf) 193 shift 1 194 builtin $program -C $conf $* 195 for (f in $manconfs) { 196 rm -f $f >[2]/dev/null 197 } 198 } 199 } 200 fn man { _man man $* } 201 fn apropos { _man apropos $* } 202 fn makewhatis { _man makewhatis $* } 203 fn gpg { builtin gpg --armor $* } 204 fn convert { 205 if (flag i) { 206 builtin convert -monitor $* 207 } else { 208 builtin convert $* 209 } 210 } 211 fn dict { 212 @{ 213 if (flag i) { 214 argv = () 215 for (arg in $*) { 216 argv = ($argv `''{printf '%s' $arg | sed -E 's~dict://[^/]*/.:(.*)~\1~'}) 217 } 218 } else { 219 argv = $* 220 } 221 builtin dict $argv 222 } 223 } 224 225 # Enable coredumps of practically infinite size. 226 limit coredumpsize 99999999 227 228 # .profile 229 INPUTRC = $home/.config/readline/inputrc 230 EDITOR = nvim 231 PAGER = less 232 TERMINAL= st 233 PASS = $home/.local/pass 234 SHELL = /bin/rc 235 236 . $home/.config/user-dirs.dirs 237 XDG_CONFIG_HOME = $home/.config 238 XDG_CACHE_HOME = $home/.cache 239 XAUTHORITY = $home/.local/.xauth 240 LESSHISTFILE = - 241 HISTFILE = $home/.local/history 242 GNUPGHOME = $home/.local/gnupg 243 IPFS_PATH = $home/.local/ipfs 244 CURLHOME = $home/.config/curl/" 245 LS_COLORS = `''{<$home/.config/ls tr -d ' ' | tr '\n' ':' | tr -s ':'} 246 247 history = $XDG_CACHE_HOME/history 248 # Originally I had $HOME/.scripts placed before the regular $PATH to override 249 # things, however this can mess with traditional unix shells that don't 250 # understand subdirs in $PATH. Say you have rm/script1 and rm/script2: rc will 251 # still run the regular /bin/rm, but sh will go 'ah, let's try execute this 252 # directory and see what happens' - of course nothing happens and it gives up 253 # on trying to locate rm. 254 path = ($path $HOME/.scripts/ /usr/lib/plan9/bin)