├── .gitignore ├── .static └── css │ └── stylesheet.css ├── LICENSE ├── README.org ├── completions ├── git.ksh ├── git.org ├── gopass.ksh ├── gopass.org ├── got.ksh ├── got.org ├── man.ksh ├── man.org ├── mpc.ksh ├── mpc.org ├── ogvt.ksh ├── ogvt.org ├── rc.ksh ├── rc.org ├── ssh.ksh ├── ssh.org ├── vmd.ksh └── vmd.org ├── extensions ├── fonts.ksh ├── fonts.org ├── fzf.ksh ├── fzf.org ├── git-prompt.ksh ├── git-prompt.org ├── got.ksh ├── got.org ├── k.ksh ├── k.org ├── keychain.ksh ├── keychain.org ├── nocolor.ksh ├── nocolor.org ├── openbsd.ksh ├── openbsd.org ├── pkgup.ksh └── pkgup.org ├── lib └── loader.ksh ├── ohmy.ksh └── prompts ├── 9.ksh ├── 9.org ├── og-openbsd.ksh ├── og-openbsd.org ├── plain.ksh ├── plain.org ├── q.ksh └── q.org /.gitignore: -------------------------------------------------------------------------------- 1 | cache/* 2 | -------------------------------------------------------------------------------- /.static/css/stylesheet.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Roboto, arial, sans-serif; 3 | } 4 | 5 | #content { 6 | width: 100%; 7 | height: 100%; 8 | } 9 | 10 | .title { 11 | 12 | } 13 | 14 | #table-of-contents { 15 | float: left; 16 | width: 25%; 17 | } 18 | 19 | #table-of-contents h2 { 20 | font-size: 20px; 21 | } 22 | 23 | .outline-2 { 24 | float: right; 25 | width: 75%; 26 | } 27 | 28 | #postamble { 29 | float: left; 30 | width: 100%; 31 | } 32 | 33 | table { 34 | border-collapse: collapse; 35 | border: 1px solid black; 36 | } 37 | 38 | th, td { 39 | text-align: left; 40 | padding: 8px; 41 | } 42 | 43 | tr:nth-child(even) { 44 | background-color: #f9fafc; 45 | } 46 | 47 | pre { 48 | border-radius: 15px; 49 | } 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Aaron Bieber 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+TITLE: ohmyksh 2 | 3 | ** About 4 | 5 | Have your cake and eat it too! 6 | 7 | ~ohmyksh~ is a framework for expanding OpenBSD's [[https://man.openbsd.org/ksh][ksh]]. It offers: 8 | 9 | - completions :: for common things like [[https://man.openbsd.org/man][man]] pages, [[https://man.openbsd.org/ssh][ssh]] ~known_hosts~ and ~git~ (and 10 | ~got~!) commands. 11 | - extensions :: to import bulk functionality, including git-prompt, OpenBSD 12 | specific tooling, disabling color.. etc. 13 | - prompts :: a decent selection of useful, minimal prompts. 14 | 15 | 16 | ** Completions 17 | 18 | | Name | Completes | 19 | |--------+----------------------------------------| 20 | | [[file:completions/git.org][git]] | add, fetch... | 21 | | [[file:completions/got.org][got]] | add, blame... | 22 | | [[file:completions/gopass.org][gopass]] | audit, config... | 23 | | [[file:completions/man.org][man]] | man pages | 24 | | [[file:completions/mpc.org][mpc]] | play, load, toggle... | 25 | | [[file:completions/rc.org][rc]] | OpenBSD rc scripts and rc commands | 26 | | [[file:completions/ssh.org][ssh]] | ssh known hosts | 27 | | [[file:completions/vmd.org][vmd]] | vmctl commands and VM names | 28 | | [[file:completions/ogvt.org][ogvt]] | reminders for ogvt (-pub, -sig, -file) | 29 | 30 | ** Extensions 31 | 32 | | Name | Description | 33 | |------------+-------------------------------------------------------------------------| 34 | | [[file:extensions/fonts.org][fonts]] | Load fonts from common locations. | 35 | | [[file:extensions/fzf.org][fzf]] | Set of interactive wrappers for things like packages and shell history. | 36 | | [[file:extensions/git-prompt.org][git-prompt]] | A port of git-prompt for KSH. | 37 | | [[file:extensions/got.org][got]] | Adds PS1 support for got, as well as a few helper functions. | 38 | | [[file:extensions/k.org][k]] | A tool to quickly change directories. | 39 | | [[file:extensions/keychain.org][keychain]] | Wrapper for [[https://www.funtoo.org/Keychain][Funtoo's Keychain]] utility. | 40 | | [[file:extensions/nocolor.org][nocolor]] | Disable terminal color options for many tools. | 41 | | [[file:extensions/openbsd.org][openbsd]] | A set of tools for working with the OpenBSD source trees. | 42 | | [[file:extensions/pkgup.org][pkgup]] | Utility to speed up OpenBSD' [[https://man.openbsd.org/pkg_add][pkg_add(1)]]. | 43 | 44 | 45 | ** Prompts 46 | 47 | | Name | Example | Extensions used | 48 | |------------+-------------------------------+-----------------| 49 | | [[file:prompts/q.org][q]] | ~qbit@litr[0]:~$~ | git-prompt, got | 50 | | [[file:prompts/plain.org][plain]] | ~litr:~/src/ohmyksh/prompts$~ | - | 51 | | [[file:prompts/og-openbsd.org][og-openbsd]] | ~$~ | - | 52 | | [[file:prompts/9.org][9]] | ~%~ | - | 53 | 54 | ** Example usage 55 | 56 | #+begin_src shell 57 | # ohmyksh needs to know where it lives, so we tell it via this env var: 58 | OHMYKSH_DIR=${HOME}/src/ohmyksh 59 | 60 | # Now we can load everything up! 61 | . ${OHMYKSH_DIR}/ohmy.ksh 62 | 63 | # All the paths we use (in order!) 64 | set -A my_paths -- \ 65 | /usr/ports/infrastructure/bin \ 66 | ~/bin \ 67 | ~/go/bin \ 68 | /usr/local/plan9/bin 69 | 70 | paths "${my_paths[@]}" 71 | 72 | # Load our various extensions 73 | load_extension fonts 74 | load_extension k 75 | load_extension nocolor 76 | load_extension openbsd 77 | 78 | # Load handy completions for various things 79 | load_completion ssh 80 | load_completion vmd 81 | load_completion rc 82 | load_completion gopass 83 | load_completion git 84 | 85 | alias vi=vim 86 | 87 | # the q prompt auto-loads the git-prompt extension 88 | set_prompt q 89 | #+end_src 90 | 91 | ** Contributing 92 | 93 | Contributions can be sent in via Github PRs or via emailing a patch to 94 | [[~qbit/ohmyksh@lists.sr.ht][~qbit/ohmyksh@lists.sr.ht]]. 95 | 96 | If you do send in a contribution, please include a .org file which describes the 97 | feature set. The org syntax is available [[https://orgmode.org/quickstart.html][here]], however, one will likely be able 98 | to just copy an existing file and modify it. 99 | 100 | -------------------------------------------------------------------------------- /completions/git.ksh: -------------------------------------------------------------------------------- 1 | #: | git | add, fetch... | 2 | set -A complete_git_1 -- \ 3 | $(git --list-cmds=main) \ 4 | $(git config --get-regexp ^alias\. | awk -F '[\. ]' '{ print $2 }') 5 | -------------------------------------------------------------------------------- /completions/git.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: git 2 | 3 | The ~git~ completion currently supports the following arguments: 4 | 5 | ** Level 1 6 | 7 | The completions for level one are dynamically created using the following 8 | commands: 9 | 10 | #+begin_src ksh 11 | $(git --list-cmds=main) \ 12 | $(git config --get-regexp ^alias\. | awk -F '[\. ]' '{ print $2 }') 13 | #+end_src 14 | -------------------------------------------------------------------------------- /completions/gopass.ksh: -------------------------------------------------------------------------------- 1 | #: | gopass | audit, config... | 2 | PASS_LIST=$(gopass ls -f) 3 | set -A complete_gopass -- $PASS_LIST agent audit binary bin clone completion config copy cp create new delete remove rm edit set find search fsck generate git-credential jsonapi otp totp hotp git grep history hist init insert list ls move mv mounts recipients setup show sync templates unclip update version xc help h 4 | -------------------------------------------------------------------------------- /completions/gopass.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: gopass 2 | 3 | ** Any level 4 | 5 | #+begin_src shell 6 | $PASS_LIST \ 7 | agent \ 8 | audit \ 9 | binary \ 10 | bin \ 11 | clone \ 12 | completion \ 13 | config \ 14 | copy \ 15 | cp \ 16 | create \ 17 | new \ 18 | delete \ 19 | remove \ 20 | rm \ 21 | edit \ 22 | set \ 23 | find \ 24 | search \ 25 | fsck \ 26 | generate \ 27 | git-credential \ 28 | jsonapi \ 29 | otp \ 30 | totp \ 31 | hotp \ 32 | git \ 33 | grep \ 34 | history \ 35 | hist \ 36 | init \ 37 | insert \ 38 | list \ 39 | ls \ 40 | move \ 41 | mv \ 42 | mounts \ 43 | recipients \ 44 | setup \ 45 | show \ 46 | sync \ 47 | templates \ 48 | unclip \ 49 | update \ 50 | version \ 51 | xc \ 52 | help \ 53 | h 54 | #+end_src 55 | -------------------------------------------------------------------------------- /completions/got.ksh: -------------------------------------------------------------------------------- 1 | set -A complete_got_1 -- \ 2 | init \ 3 | import im \ 4 | clone cl \ 5 | fetch fe \ 6 | checkout co \ 7 | update up \ 8 | status st \ 9 | log \ 10 | diff di \ 11 | blame bl \ 12 | tree tr \ 13 | ref \ 14 | branch br \ 15 | tag \ 16 | add \ 17 | remove rm \ 18 | revert rv \ 19 | commit ci \ 20 | cherrypick cy \ 21 | backout bo \ 22 | rebase rb \ 23 | histedit he \ 24 | integrate ig \ 25 | stage sg \ 26 | unstage ug \ 27 | cat \ 28 | info 29 | -------------------------------------------------------------------------------- /completions/got.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: got 2 | 3 | The ~got~ completion currently supports the following arguments: 4 | 5 | ** Level 1 6 | #+begin_src ksh 7 | init \ 8 | import im \ 9 | clone cl \ 10 | fetch fe \ 11 | checkout co \ 12 | update up \ 13 | status st \ 14 | log \ 15 | diff di \ 16 | blame bl \ 17 | tree tr \ 18 | ref \ 19 | branch br \ 20 | tag \ 21 | add \ 22 | remove rm \ 23 | revert rv \ 24 | commit ci \ 25 | cherrypick cy \ 26 | backout bo \ 27 | rebase rb \ 28 | histedit he \ 29 | integrate ig \ 30 | stage sg \ 31 | unstage ug \ 32 | cat \ 33 | info 34 | 35 | #+end_src 36 | -------------------------------------------------------------------------------- /completions/man.ksh: -------------------------------------------------------------------------------- 1 | #: | man | man pages | 2 | MAN_CACHE=$LOAD_PATH/cache/man 3 | if [ ! -f $MAN_CACHE ]; then 4 | mkdir -p $(dirname ${MAN_CACHE}) 5 | for i in /usr{,/X11R6,/local}{,/share}/man/{,cat,man}[1-9lnp]{,f,p} 6 | do 7 | test -d $i && ls $i 8 | done | rev | cut -d. -f2- | rev | sort -u > $MAN_CACHE 9 | fi 10 | 11 | set -A complete_man -- $(cat $MAN_CACHE) 12 | -------------------------------------------------------------------------------- /completions/man.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: man 2 | 3 | ** Leven 1 4 | 5 | Completions for man pages are found via: 6 | 7 | #+begin_src shell 8 | for i in /usr{,/X11R6,/local}{,/share}/man/{,cat,man}[1-9lnp]{,f,p} 9 | do 10 | test -d $i && ls $i 11 | done | rev | cut -d. -f2- | rev | sort -u > $MAN_CACHE 12 | #+end_src 13 | 14 | Currently the cache is never re-created. Operating without a cache causes 15 | significant load times. If one requires the cache to be refreshed they can run 16 | the following in ~.xsession~ or similar: 17 | 18 | #+begin_src shell 19 | rm -f ${LOAD_PATH}/cache/man 20 | #+end_src 21 | -------------------------------------------------------------------------------- /completions/mpc.ksh: -------------------------------------------------------------------------------- 1 | set -A complete_mpc_1 -- \ 2 | add \ 3 | cdprev channels clear clearerror \ 4 | consume crop crossfade current \ 5 | del disable \ 6 | enable \ 7 | find findadd \ 8 | idle idleloop insert \ 9 | list listall load ls lsplaylists \ 10 | mixrampdb mixrampdelay move \ 11 | next \ 12 | outputs outputset \ 13 | pause pause-if-playing play playlist prev prio \ 14 | random repeat replaygain rescan rm \ 15 | save search searchadd searchplay seek \ 16 | sendmessage shuffle single stats \ 17 | sticker stop subscribe \ 18 | toggle toggleoutput \ 19 | update \ 20 | version volume \ 21 | waitmessage 22 | 23 | set -A complete_mpc_2 -- $(mpc lsplaylists | sort) 24 | -------------------------------------------------------------------------------- /completions/mpc.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: mpc 2 | 3 | ** Level 1 4 | 5 | The following completions are available for level one on MPC. 6 | 7 | #+begin_src shell 8 | add \ 9 | cdprev channels clear clearerror \ 10 | consume crop crossfade current \ 11 | del disable \ 12 | enable \ 13 | find findadd \ 14 | idle idleloop insert \ 15 | list listall load ls lsplaylists \ 16 | mixrampdb mixrampdelay move \ 17 | next \ 18 | outputs outputset \ 19 | pause pause-if-playing play playlist prev prio \ 20 | random repeat replaygain rescan rm \ 21 | save search searchadd searchplay seek \ 22 | sendmessage shuffle single stats \ 23 | sticker stop subscribe \ 24 | toggle toggleoutput \ 25 | update \ 26 | version volume \ 27 | waitmessage 28 | #+end_src 29 | 30 | ** Level 2 31 | 32 | #+begin_src shell 33 | set -A complete_mpc_2 -- $(mpc lsplaylists | sort) 34 | #+end_src 35 | 36 | *Note:* Level 2 is only populated if ~mpd~ is running. 37 | -------------------------------------------------------------------------------- /completions/ogvt.ksh: -------------------------------------------------------------------------------- 1 | set -A complete_ogvt -- \ 2 | -file \ 3 | -pub \ 4 | -sig 5 | -------------------------------------------------------------------------------- /completions/ogvt.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completion: ogvt 2 | 3 | Completions for [[https://pkg.go.dev/suah.dev/ogvt][ogvt]]. 4 | 5 | ** All levels 6 | 7 | #+begin_src ksh 8 | -file \ 9 | -pub \ 10 | -sig 11 | #+end_src 12 | -------------------------------------------------------------------------------- /completions/rc.ksh: -------------------------------------------------------------------------------- 1 | #: | rc | OpenBSD rc scripts and rc commands | 2 | set -A complete_rcctl_1 -- disable enable get ls order set restart start stop 3 | set -A complete_rcctl_2 -- $(rcctl ls all) 4 | -------------------------------------------------------------------------------- /completions/rc.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: rc 2 | 3 | ** Level 1 4 | 5 | #+begin_src shell 6 | disable enable get ls order set restart start stop 7 | #+end_src 8 | 9 | ** Level 2 10 | 11 | #+begin_src shell 12 | $(rcctl ls all) 13 | #+end_src 14 | -------------------------------------------------------------------------------- /completions/ssh.ksh: -------------------------------------------------------------------------------- 1 | #: | ssh | ssh known hosts | 2 | read_known_hosts() { 3 | local _file=$1 _line _host 4 | 5 | while read _line ; do 6 | _line=${_line%%#*} # delete comments 7 | _line=${_line%%@*} # ignore markers 8 | _line=${_line%% *} # keep only host field 9 | 10 | [[ -z $_line ]] && continue 11 | 12 | local IFS=, 13 | for _host in $_line; do 14 | _host=${_host#\[} 15 | _host=${_host%%\]*} 16 | for i in ${HOST_LIST[*]}; do 17 | [[ $_host == $i ]] && continue 2 18 | done 19 | set -s -A HOST_LIST ${HOST_LIST[*]} $_host 20 | done 21 | done <$_file 22 | } 23 | 24 | [[ -s /etc/ssh/ssh_known_hosts ]] && read_known_hosts /etc/ssh/ssh_known_hosts 25 | [[ -s ~/.ssh/known_hosts ]] && read_known_hosts ~/.ssh/known_hosts 26 | 27 | set -A complete_ssh -- ${HOST_LIST[*]} 28 | set -A complete_scp -- ${HOST_LIST[*]} 29 | set -A complete_mosh -- ${HOST_LIST[*]} 30 | -------------------------------------------------------------------------------- /completions/ssh.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: ssh 2 | 3 | ** All Levels 4 | 5 | #+begin_src shell 6 | ${HOST_LIST[*]} 7 | #+end_src 8 | 9 | ~HOST_LIST~ is a combination of ~/etc/ssh/ssh_known_hosts~ and 10 | ~~/.ssh/known_hosts~. 11 | -------------------------------------------------------------------------------- /completions/vmd.ksh: -------------------------------------------------------------------------------- 1 | #: | vmd | vmctl commands and VM names | 2 | pgrep -fq '/usr/sbin/vmd' 3 | if [ $? = 0 ]; then 4 | set -A complete_vmctl_1 -- console load reload start stop reset status send receive 5 | set -A complete_vmctl -- $(vmctl status | awk '!/NAME/{print $NF}') 6 | 7 | fi 8 | -------------------------------------------------------------------------------- /completions/vmd.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Completions: vmd 2 | 3 | *Note:* Completions are only loaded if ~vmd~ is running. 4 | 5 | ** Level 1 6 | 7 | #+begin_src shell 8 | console load reload start stop reset status send receive 9 | #+end_src 10 | 11 | ** All Levels 12 | 13 | #+begin_src shell 14 | $(vmctl status | awk '!/NAME/{print $NF}') 15 | #+end_src 16 | 17 | 18 | -------------------------------------------------------------------------------- /extensions/fonts.ksh: -------------------------------------------------------------------------------- 1 | if [ ! -z $DISPLAY ]; then 2 | [[ -d ~/.fonts ]] && xset +fp ~/.fonts 2>/dev/null 3 | [[ -d ~/.local/share/fonts ]] && xset +fp ~/.local/share/fonts/ 2>/dev/null 4 | 5 | for font in /usr/local/share/fonts/*; do 6 | xset +fp "${font}" 2>/dev/null 7 | done 8 | 9 | xset fp rehash 10 | fi 11 | -------------------------------------------------------------------------------- /extensions/fonts.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Extensions: fonts 2 | 3 | ** Load fonts from common locations 4 | 5 | If ~$DISPLAY~ is set, the ~fonts~ extension will load fonts from common 6 | locations. 7 | 8 | Currently the locations are: 9 | 10 | | Directory | Recursive | 11 | |--------------------------+-----------| 12 | | ~/.fonts | no | 13 | | ~/.local/share/fonts | no | 14 | | /usr/local/share/fonts/* | yes | 15 | 16 | -------------------------------------------------------------------------------- /extensions/fzf.ksh: -------------------------------------------------------------------------------- 1 | zpatch() { 2 | if [ -z $OHMYPATCHES ]; then 3 | echo "please set OHMYPATCHES to the directory that contains your patches." 4 | return 1 5 | fi 6 | 7 | local _patch_file="$(ls ${OHMYPATCHES}/* | fzf)" 8 | /usr/bin/patch $@ < "${_patch_file}" 9 | } 10 | 11 | zh() { 12 | fc -ln | eval $(fzf) 13 | } 14 | 15 | zpkg() { 16 | local _pkg _usage 17 | 18 | _usage="zpkg add|rm" 19 | 20 | if [ ! -f /usr/local/share/sqlports ]; then 21 | echo "please install sqlports" 22 | return 1 23 | fi 24 | 25 | if [ ! -e /usr/local/bin/sqlite3 ]; then 26 | echo "please install sqlite3" 27 | return 1 28 | fi 29 | 30 | if [ -z $1 ]; then 31 | echo $_usage 32 | return 1 33 | else 34 | case $1 in 35 | add) 36 | _pkg=$(/usr/local/bin/sqlite3 -separator " " \ 37 | /usr/local/share/sqlports \ 38 | "select distinct fullpkgname from Ports;" |\ 39 | fzf --preview "/usr/sbin/pkg_info {1}") 40 | [ ! -z $_pkg ] && ${OHMY_DO} /usr/sbin/pkg_add $_pkg 41 | ;; 42 | rm) 43 | _pkg=$(ls -1 /var/db/pkg | fzf --preview "/usr/sbin/pkg_info {1}") 44 | [ ! -z $_pkg ] && ${OHMY_DO} /usr/sbin/pkg_delete $_pkg 45 | ;; 46 | *) 47 | echo $_usage 48 | esac 49 | fi 50 | } 51 | -------------------------------------------------------------------------------- /extensions/fzf.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Extensions: fzf 2 | 3 | ** Functions 4 | | Name | Description | 5 | |------+---------------------------------| 6 | | zh | Interactive shell history. | 7 | | zpkg | Interactive package add/remove. | 8 | | zpatch | Interactive function for applying patches. | 9 | 10 | 11 | -------------------------------------------------------------------------------- /extensions/git-prompt.ksh: -------------------------------------------------------------------------------- 1 | # ksh git prompt support 2 | # 3 | # Copyright (C) 2013,2016,2019 Aaron Bieber 4 | # Copyright (C) 2006,2007 Shawn O. Pearce 5 | # Distributed under the GNU General Public License, version 2.0. 6 | # 7 | # This script allows you to see repository status in your prompt. 8 | # 9 | # To enable: 10 | # 11 | # 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh). 12 | # 2) Add the following line to your .bashrc/.zshrc: 13 | # source ~/.git-prompt.sh 14 | # 3a) Change your PS1 to call __git_ps1 as 15 | # command-substitution: 16 | # Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' 17 | # ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' 18 | # the optional argument will be used as format string. 19 | # 3b) Alternatively, for a slightly faster prompt, __git_ps1 can 20 | # be used for PROMPT_COMMAND in Bash or for precmd() in Zsh 21 | # with two parameters,
 and , which are strings
 22 | #        you would put in $PS1 before and after the status string
 23 | #        generated by the git-prompt machinery.  e.g.
 24 | #        Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
 25 | #          will show username, at-sign, host, colon, cwd, then
 26 | #          various status string, followed by dollar and SP, as
 27 | #          your prompt.
 28 | #        ZSH:  precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
 29 | #          will show username, pipe, then various status string,
 30 | #          followed by colon, cwd, dollar and SP, as your prompt.
 31 | #        Optionally, you can supply a third argument with a printf
 32 | #        format string to finetune the output of the branch status
 33 | #
 34 | # The repository status will be displayed only if you are currently in a
 35 | # git repository. The %s token is the placeholder for the shown status.
 36 | #
 37 | # The prompt status always includes the current branch name.
 38 | #
 39 | # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
 40 | # unstaged (*) and staged (+) changes will be shown next to the branch
 41 | # name.  You can configure this per-repository with the
 42 | # bash.showDirtyState variable, which defaults to true once
 43 | # GIT_PS1_SHOWDIRTYSTATE is enabled.
 44 | #
 45 | # You can also see if currently something is stashed, by setting
 46 | # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
 47 | # then a '$' will be shown next to the branch name.
 48 | #
 49 | # If you would like to see if there're untracked files, then you can set
 50 | # GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
 51 | # files, then a '%' will be shown next to the branch name.  You can
 52 | # configure this per-repository with the bash.showUntrackedFiles
 53 | # variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
 54 | # enabled.
 55 | #
 56 | # If you would like to see the difference between HEAD and its upstream,
 57 | # set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates you are behind, ">"
 58 | # indicates you are ahead, "<>" indicates you have diverged and "="
 59 | # indicates that there is no difference. You can further control
 60 | # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
 61 | # of values:
 62 | #
 63 | #     verbose       show number of commits ahead/behind (+/-) upstream
 64 | #     name          if verbose, then also show the upstream abbrev name
 65 | #     legacy        don't use the '--count' option available in recent
 66 | #                   versions of git-rev-list
 67 | #     git           always compare HEAD to @{upstream}
 68 | #     svn           always compare HEAD to your SVN upstream
 69 | #
 70 | # You can change the separator between the branch name and the above
 71 | # state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
 72 | # is SP.
 73 | #
 74 | # By default, __git_ps1 will compare HEAD to your SVN upstream if it can
 75 | # find one, or @{upstream} otherwise.  Once you have set
 76 | # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
 77 | # setting the bash.showUpstream config variable.
 78 | #
 79 | # If you would like to see more information about the identity of
 80 | # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
 81 | # to one of these values:
 82 | #
 83 | #     contains      relative to newer annotated tag (v1.6.3.2~35)
 84 | #     branch        relative to newer tag or branch (master~4)
 85 | #     describe      relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
 86 | #     default       exactly matching tag
 87 | #
 88 | # If you would like a colored hint about the current dirty state, set
 89 | # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 90 | # the colored output of "git status -sb" and are available only when
 91 | # using __git_ps1 for PROMPT_COMMAND or precmd.
 92 | #
 93 | # If you would like __git_ps1 to do nothing in the case when the current
 94 | # directory is set up to be ignored by git, then set
 95 | # GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
 96 | # repository level by setting bash.hideIfPwdIgnored to "false".
 97 | 
 98 | # check whether printf supports -v
 99 | __git_printf_supports_v=
100 | printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
101 | 
102 | # stores the divergence from upstream in $p
103 | # used by GIT_PS1_SHOWUPSTREAM
104 | __git_ps1_show_upstream ()
105 | {
106 | 	local key value
107 | 	local svn_remote svn_url_pattern count n
108 | 	local upstream=git legacy="" verbose="" name=""
109 | 
110 | 	set -A svn_remote
111 | 	# get some config options from git-config
112 | 	set -A output $(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
113 | 	count=0
114 | 	for idx in ${output[@]}; do
115 | 		if [ $((count % 2)) == 0 ]; then
116 | 			key=${output[$count]}
117 | 			value=${output[$((count+1))]}
118 | 		fi
119 | 
120 | 		case "$key" in
121 | 		bash.showupstream)
122 | 			GIT_PS1_SHOWUPSTREAM="$value"
123 | 			if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
124 | 				p=""
125 | 				return
126 | 			fi
127 | 			;;
128 | 		svn-remote.*.url)
129 | 			svn_remote[$((${#svn_remote[@]} + 1))]="$value"
130 | 			svn_url_pattern="$svn_url_pattern\\|$value"
131 | 			upstream=svn+git # default upstream is SVN if available, else git
132 | 			;;
133 | 		esac
134 | 		((count=count+1))
135 | 	done
136 | 
137 | 	# parse configuration values
138 | 	for option in ${GIT_PS1_SHOWUPSTREAM}; do
139 | 		case "$option" in
140 | 		git|svn) upstream="$option" ;;
141 | 		verbose) verbose=1 ;;
142 | 		legacy)  legacy=1  ;;
143 | 		name)    name=1 ;;
144 | 		esac
145 | 	done
146 | 
147 | 	# Find our upstream
148 | 	case "$upstream" in
149 | 	git)    upstream="@{upstream}" ;;
150 | 	svn*)
151 | 		# get the upstream from the "git-svn-id: ..." in a commit message
152 | 		# (git-svn uses essentially the same procedure internally)
153 | 		set -A svn_upstream $(git log --first-parent -1 \
154 | 					--grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null)
155 | 		if [[ 0 -ne ${#svn_upstream[@]} ]]; then
156 | 			svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
157 | 			svn_upstream=${svn_upstream%@*}
158 | 			local n_stop="${#svn_remote[@]}"
159 | 			#for ((n=1; n <= n_stop; n++)); do
160 | 			local count=1;
161 | echo n_stop;
162 | 			for n in n_stop; do
163 | 				svn_upstream=${svn_upstream#${svn_remote[$count]}}
164 | 				((count=count+1))
165 | 			done
166 | 
167 | 			if [[ -z "$svn_upstream" ]]; then
168 | 				# default branch name for checkouts with no layout:
169 | 				upstream=${GIT_SVN_ID:-git-svn}
170 | 			else
171 | 				upstream=${svn_upstream#/}
172 | 			fi
173 | 		elif [[ "svn+git" = "$upstream" ]]; then
174 | 			upstream="@{upstream}"
175 | 		fi
176 | 		;;
177 | 	esac
178 | 
179 | 	# Find how many commits we are ahead/behind our upstream
180 | 	if [[ -z "$legacy" ]]; then
181 | 		count="$(git rev-list --count --left-right \
182 | 				"$upstream"...HEAD 2>/dev/null)"
183 | 	else
184 | 		# produce equivalent output to --count for older versions of git
185 | 		local commits
186 | 		if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
187 | 		then
188 | 			local commit behind=0 ahead=0
189 | 			for commit in $commits
190 | 			do
191 | 				case "$commit" in
192 | 				"<"*) ((behind++)) ;;
193 | 				*)    ((ahead++))  ;;
194 | 				esac
195 | 			done
196 | 			count="$behind	$ahead"
197 | 		else
198 | 			count=""
199 | 		fi
200 | 	fi
201 | 
202 | 	# calculate the result
203 | 	if [[ -z "$verbose" ]]; then
204 | 		case "$count" in
205 | 		"") # no upstream
206 | 			p="" ;;
207 | 		"0	0") # equal to upstream
208 | 			p="=" ;;
209 | 		"0	"*) # ahead of upstream
210 | 			p=">" ;;
211 | 		*"	0") # behind upstream
212 | 			p="<" ;;
213 | 		*)	    # diverged from upstream
214 | 			p="<>" ;;
215 | 		esac
216 | 	else
217 | 		case "$count" in
218 | 		"") # no upstream
219 | 			p="" ;;
220 | 		"0	0") # equal to upstream
221 | 			p=" u=" ;;
222 | 		"0	"*) # ahead of upstream
223 | 			p=" u+${count#0	}" ;;
224 | 		*"	0") # behind upstream
225 | 			p=" u-${count%	0}" ;;
226 | 		*)	    # diverged from upstream
227 | 			p=" u+${count#*	}-${count%	*}" ;;
228 | 		esac
229 | 		if [[ -n "$count" && -n "$name" ]]; then
230 | 			__git_ps1_upstream_name=$(git rev-parse \
231 | 				--abbrev-ref "$upstream" 2>/dev/null)
232 | 			if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
233 | 				p="$p \${__git_ps1_upstream_name}"
234 | 			else
235 | 				p=$(echo "$p ${__git_ps1_upstream_name}" | sed 's/\n//g')
236 | 				# not needed anymore; keep user's
237 | 				# environment clean
238 | 				unset __git_ps1_upstream_name
239 | 			fi
240 | 		fi
241 | 	fi
242 | 
243 | }
244 | 
245 | # Helper function that is meant to be called from __git_ps1.  It
246 | # injects color codes into the appropriate gitstring variables used
247 | # to build a gitstring.
248 | __git_ps1_colorize_gitstring ()
249 | {
250 | 	if [[ -n ${ZSH_VERSION-} ]]; then
251 | 		local c_red='%F{red}'
252 | 		local c_green='%F{green}'
253 | 		local c_lblue='%F{blue}'
254 | 		local c_clear='%f'
255 | 	else
256 | 		# Using \[ and \] around colors is necessary to prevent
257 | 		# issues with command line editing/browsing/completion!
258 | 		local c_red='\[\e[31m\]'
259 | 		local c_green='\[\e[32m\]'
260 | 		local c_lblue='\[\e[1;34m\]'
261 | 		local c_clear='\[\e[0m\]'
262 | 	fi
263 | 	local bad_color=$c_red
264 | 	local ok_color=$c_green
265 | 	local flags_color="$c_lblue"
266 | 
267 | 	local branch_color=""
268 | 	if [ $detached = no ]; then
269 | 		branch_color="$ok_color"
270 | 	else
271 | 		branch_color="$bad_color"
272 | 	fi
273 | 	c="$branch_color$c"
274 | 
275 | 	z="$c_clear$z"
276 | 	if [ "$w" = "*" ]; then
277 | 		w="$bad_color$w"
278 | 	fi
279 | 	if [ -n "$i" ]; then
280 | 		i="$ok_color$i"
281 | 	fi
282 | 	if [ -n "$s" ]; then
283 | 		s="$flags_color$s"
284 | 	fi
285 | 	if [ -n "$u" ]; then
286 | 		u="$bad_color$u"
287 | 	fi
288 | 	r="$c_clear$r"
289 | }
290 | 
291 | __git_eread ()
292 | {
293 | 	local f="$1"
294 | 	shift
295 | 	test -r "$f" && read "$@" <"$f"
296 | }
297 | 
298 | # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
299 | # when called from PS1 using command substitution
300 | # in this mode it prints text to add to bash PS1 prompt (includes branch name)
301 | #
302 | # __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc)
303 | # in that case it _sets_ PS1. The arguments are parts of a PS1 string.
304 | # when two arguments are given, the first is prepended and the second appended
305 | # to the state string when assigned to PS1.
306 | # The optional third parameter will be used as printf format string to further
307 | # customize the output of the git-status string.
308 | # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
309 | __git_ps1 ()
310 | {
311 | 	# preserve exit status
312 | 	local exit=$?
313 | 	local pcmode=no
314 | 	local detached=no
315 | 	local ps1pc_start='\u@\h:\w '
316 | 	local ps1pc_end='\$ '
317 | 	local printf_format=' (%s)'
318 | 
319 | 	case "$#" in
320 | 		2|3)	pcmode=yes
321 | 			ps1pc_start="$1"
322 | 			ps1pc_end="$2"
323 | 			printf_format="${3:-$printf_format}"
324 | 			# set PS1 to a plain prompt so that we can
325 | 			# simply return early if the prompt should not
326 | 			# be decorated
327 | 			PS1="$ps1pc_start$ps1pc_end"
328 | 		;;
329 | 		0|1)	printf_format="${1:-$printf_format}"
330 | 		;;
331 | 		*)	return $exit
332 | 		;;
333 | 	esac
334 | 
335 | 	# ps1_expanded:  This variable is set to 'yes' if the shell
336 | 	# subjects the value of PS1 to parameter expansion:
337 | 	#
338 | 	#   * bash does unless the promptvars option is disabled
339 | 	#   * zsh does not unless the PROMPT_SUBST option is set
340 | 	#   * POSIX shells always do
341 | 	#
342 | 	# If the shell would expand the contents of PS1 when drawing
343 | 	# the prompt, a raw ref name must not be included in PS1.
344 | 	# This protects the user from arbitrary code execution via
345 | 	# specially crafted ref names.  For example, a ref named
346 | 	# 'refs/heads/$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' might cause the
347 | 	# shell to execute 'sudo rm -rf /' when the prompt is drawn.
348 | 	#
349 | 	# Instead, the ref name should be placed in a separate global
350 | 	# variable (in the __git_ps1_* namespace to avoid colliding
351 | 	# with the user's environment) and that variable should be
352 | 	# referenced from PS1.  For example:
353 | 	#
354 | 	#     __git_ps1_foo=$(do_something_to_get_ref_name)
355 | 	#     PS1="...stuff...\${__git_ps1_foo}...stuff..."
356 | 	#
357 | 	# If the shell does not expand the contents of PS1, the raw
358 | 	# ref name must be included in PS1.
359 | 	#
360 | 	# The value of this variable is only relevant when in pcmode.
361 | 	#
362 | 	# Assume that the shell follows the POSIX specification and
363 | 	# expands PS1 unless determined otherwise.  (This is more
364 | 	# likely to be correct if the user has a non-bash, non-zsh
365 | 	# shell and safer than the alternative if the assumption is
366 | 	# incorrect.)
367 | 	#
368 | 	local ps1_expanded=yes
369 | 	[ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
370 | 	[ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
371 | 
372 | 	local repo_info rev_parse_exit_code
373 | 	set -A repo_info $(git rev-parse --git-dir --is-inside-git-dir \
374 | 		--is-bare-repository --is-inside-work-tree \
375 | 		--short HEAD 2>/dev/null)
376 | 	rev_parse_exit_code="$?"
377 | 
378 | 	if [ -z "$repo_info" ]; then
379 | 		return $exit
380 | 	fi
381 | 
382 | 	local short_sha=""
383 | 	idx=${#repo_info[@]}
384 | 	((idx=idx-1))
385 | 	if [ "$rev_parse_exit_code" = "0" ]; then
386 | 		short_sha="${repo_info[$idx]}"
387 | 		((idx=idx-1))
388 | 	fi
389 | 	local inside_worktree="${repo_info[$idx]}"
390 | 	((idx=idx-1))
391 | 	local bare_repo="${repo_info[$idx]}"
392 | 	((idx=idx-1))
393 | 	local inside_gitdir="${repo_info[$idx]}"
394 | 	((idx=idx-1))
395 | 	local g="${repo_info[0]}"
396 | 
397 | 	if [ "true" = "$inside_worktree" ] &&
398 | 	   [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] &&
399 | 	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
400 | 	   git check-ignore -q .
401 | 	then
402 | 		return $exit
403 | 	fi
404 | 
405 | 	local r=""
406 | 	local b=""
407 | 	local step=""
408 | 	local total=""
409 | 	if [ -d "$g/rebase-merge" ]; then
410 | 		__git_eread "$g/rebase-merge/head-name" b
411 | 		__git_eread "$g/rebase-merge/msgnum" step
412 | 		__git_eread "$g/rebase-merge/end" total
413 | 		if [ -f "$g/rebase-merge/interactive" ]; then
414 | 			r="|REBASE-i"
415 | 		else
416 | 			r="|REBASE-m"
417 | 		fi
418 | 	else
419 | 		if [ -d "$g/rebase-apply" ]; then
420 | 			__git_eread "$g/rebase-apply/next" step
421 | 			__git_eread "$g/rebase-apply/last" total
422 | 			if [ -f "$g/rebase-apply/rebasing" ]; then
423 | 				__git_eread "$g/rebase-apply/head-name" b
424 | 				r="|REBASE"
425 | 			elif [ -f "$g/rebase-apply/applying" ]; then
426 | 				r="|AM"
427 | 			else
428 | 				r="|AM/REBASE"
429 | 			fi
430 | 		elif [ -f "$g/MERGE_HEAD" ]; then
431 | 			r="|MERGING"
432 | 		elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
433 | 			r="|CHERRY-PICKING"
434 | 		elif [ -f "$g/REVERT_HEAD" ]; then
435 | 			r="|REVERTING"
436 | 		elif [ -f "$g/BISECT_LOG" ]; then
437 | 			r="|BISECTING"
438 | 		fi
439 | 
440 | 		if [ -n "$b" ]; then
441 | 			:
442 | 		elif [ -h "$g/HEAD" ]; then
443 | 			# symlink symbolic ref
444 | 			b="$(git symbolic-ref HEAD 2>/dev/null)"
445 | 		else
446 | 			local head=""
447 | 			if ! __git_eread "$g/HEAD" head; then
448 | 				return $exit
449 | 			fi
450 | 			# is it a symbolic ref?
451 | 			b="${head#ref: }"
452 | 			if [ "$head" = "$b" ]; then
453 | 				detached=yes
454 | 				b="$(
455 | 				case "${GIT_PS1_DESCRIBE_STYLE-}" in
456 | 				(contains)
457 | 					git describe --contains HEAD ;;
458 | 				(branch)
459 | 					git describe --contains --all HEAD ;;
460 | 				(describe)
461 | 					git describe HEAD ;;
462 | 				(* | default)
463 | 					git describe --tags --exact-match HEAD ;;
464 | 				esac 2>/dev/null)" ||
465 | 
466 | 				b="$short_sha..."
467 | 				b="($b)"
468 | 			fi
469 | 		fi
470 | 	fi
471 | 
472 | 	if [ -n "$step" ] && [ -n "$total" ]; then
473 | 		r="$r $step/$total"
474 | 	fi
475 | 
476 | 	local w=""
477 | 	local i=""
478 | 	local s=""
479 | 	local u=""
480 | 	local c=""
481 | 	local p=""
482 | 
483 | 	if [ "true" = "$inside_gitdir" ]; then
484 | 		if [ "true" = "$bare_repo" ]; then
485 | 			c="BARE:"
486 | 		else
487 | 			b="GIT_DIR!"
488 | 		fi
489 | 	elif [ "true" = "$inside_worktree" ]; then
490 | 		if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
491 | 		   [ "$(git config --bool bash.showDirtyState)" != "false" ]
492 | 		then
493 | 			git diff --no-ext-diff --quiet || w="*"
494 | 			git diff --no-ext-diff --cached --quiet || i="+"
495 | 			if [ -z "$short_sha" ] && [ -z "$i" ]; then
496 | 				i="#"
497 | 			fi
498 | 		fi
499 | 		if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
500 | 		   git rev-parse --verify --quiet refs/stash >/dev/null
501 | 		then
502 | 			s="$"
503 | 		fi
504 | 
505 | 		if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
506 | 		   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
507 | 		   git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
508 | 		then
509 | 			u="%${ZSH_VERSION+%}"
510 | 		fi
511 | 
512 | 		if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
513 | 			__git_ps1_show_upstream
514 | 		fi
515 | 	fi
516 | 
517 | 	local z="${GIT_PS1_STATESEPARATOR-" "}"
518 | 
519 | 	# NO color option unless in PROMPT_COMMAND mode
520 | 	if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
521 | 		__git_ps1_colorize_gitstring
522 | 	fi
523 | 
524 | 	b=${b##refs/heads/}
525 | 	if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
526 | 		__git_ps1_branch_name=$b
527 | 		b="\${__git_ps1_branch_name}"
528 | 	fi
529 | 
530 | 	local f="$w$i$s$u"
531 | 	local gitstring="$c$b${f:+$z$f}$r$p"
532 | 
533 | 	if [ $pcmode = yes ]; then
534 | 		if [ "${__git_printf_supports_v-}" != yes ]; then
535 | 			gitstring=$(printf -- "$printf_format" "$gitstring")
536 | 		else
537 | 			printf -v gitstring -- "$printf_format" "$gitstring"
538 | 		fi
539 | 		PS1="$ps1pc_start$gitstring$ps1pc_end"
540 | 	else
541 | 		printf -- "$printf_format" "$gitstring"
542 | 	fi
543 | 
544 | 	return $exit
545 | }
546 | 
547 | 


--------------------------------------------------------------------------------
/extensions/git-prompt.org:
--------------------------------------------------------------------------------
1 | #+TITLE: Extensions: git-prompt
2 | 
3 | ** About
4 | 
5 | This extension is a port of git's [[https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh][contrib git-prompt]] script to OpenBSD's ksh.
6 | 
7 | It allows one to include git information in your PS1 or other scripts.
8 | 
9 | 


--------------------------------------------------------------------------------
/extensions/got.ksh:
--------------------------------------------------------------------------------
 1 | #!/bin/ksh
 2 | 
 3 | # Thanks to jrick for this one:
 4 | # https://gist.github.com/jrick/d47e1be98609401e86ba0bd6bfbfc8fe
 5 | function got-push {
 6 |         local r
 7 | 	r=$(set -e; got info | awk '$1 ~ "^repository:" {print $2}')
 8 | 	[ -z "$r" ] && return 1
 9 | 	(cd "$r" && git push "$@")
10 | }
11 | 
12 | function got-sync {
13 | 	local _remote _info _branch
14 | 	_remote=$1
15 | 	_info="$(got info)"
16 | 	_branch="$(echo "$_info" | awk '/branch reference:/ {l = split($NF, a, "/"); print a[l]}')"
17 | 	[ -z $_remote ] && _remote="origin"
18 | 	[ -z $_branch ] && _branch="main"
19 | 	got fetch "$_remote" && got update -b "$_remote/$_branch" && \
20 | 		got rebase $_branch
21 | }
22 | 
23 | function got-clean {
24 | 	local _opt
25 | 	_opt=$1
26 | 	for f in $(got status | grep ^? | awk '{print $2}'); do
27 | 		case "$_opt" in
28 | 			-f)
29 | 				rm -vf "$f"
30 | 				;;
31 | 			-i)
32 | 				rm -vi "$f"
33 | 				;;
34 | 			*)
35 | 				echo "Use -f or -i to actually remove files."
36 | 				echo "rm $f"
37 | 				;;
38 | 		esac
39 | 	done
40 | }
41 | 
42 | function got-commit-v {
43 | 	local _width _session _args
44 | 
45 | 	_args="$@"
46 | 
47 | 	tmux split-window -p 60
48 | 
49 | 	tmux select-pane -t 2
50 | 	tmux send-keys "got diff $_args | less" C-m
51 | 
52 | 	tmux select-pane -t 1
53 | 	tmux send-keys "clear" C-m
54 | 	tmux send-keys "got commit $_args"
55 | }
56 | 
57 | function __got_ps1 {
58 | 	local _format _branch _status
59 | 	_format=$1
60 | 	_branch=$(got branch 2>/dev/null | grep -v conf_set_now)
61 | 	_status=$?	
62 | 	if [ $_status == 0 ]; then
63 | 		printf "$_format" $_branch
64 | 	fi
65 | }
66 | 


--------------------------------------------------------------------------------
/extensions/got.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Extensions: got
 2 | 
 3 | ** Helper Functions
 4 | 
 5 | This extension adds helper functions to the [[https://gameoftrees.org/][got]] tool.
 6 | 
 7 | | Function    | Options                                         | Description                                                             |
 8 | |-------------+-------------------------------------------------+-------------------------------------------------------------------------|
 9 | | ~got-clean~ | -f remove files, -i remove files interactively. | Cleans the work directory.                                              |
10 | | ~got-push~  | All ~get push~ options supported.               | Pushes (~git push~) from the bare repository found in ~.got/repository~ |
11 | | ~got-sync~  | Remote can be specified as the first argument.  | Rebase ~master~ on top of ~[remote]/master~. Defaults to ~origin~.      |
12 | | ~__got_ps1~ | -                                               | Current got branch. Intended to be used in ~$PS1~.                      |
13 | 
14 | 


--------------------------------------------------------------------------------
/extensions/k.ksh:
--------------------------------------------------------------------------------
 1 | #!/bin/ksh
 2 | 
 3 | # Copyright (c) 2019 Aaron Bieber 
 4 | #
 5 | # Permission to use, copy, modify, and distribute this software for any
 6 | # purpose with or without fee is hereby granted, provided that the above
 7 | # copyright notice and this permission notice appear in all copies.
 8 | #
 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 | 
17 | k() {
18 | 	${K_DEBUG}
19 | 	if [ -z $1 ]; then
20 | 		echo $PWD >> ~/.k
21 | 	else
22 | 		K=~/.k
23 | 		case $1 in
24 | 		clean)	sort -u $K -o ${K};;
25 | 		rm)	sed -i -E "\#^${2:-${PWD}}\$#d" ${K};;
26 | 		ls)	cat ${K};;
27 | 		*)	cd "$(grep -e "$1" ${K} | head -n 1)";;
28 | 		esac
29 | 	fi
30 | }
31 | 


--------------------------------------------------------------------------------
/extensions/k.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Extension: k
 2 | 
 3 | ~k~ is a function that allows one to quickly jump to directories based off
 4 | simple pattern matching.
 5 | 
 6 | ** Usage
 7 | 
 8 | *** Jumping to known locations
 9 | 
10 | #+begin_src shell
11 |   qbit@tal[0]:~$ k ohmy
12 |   qbit@tal[0]:~/src/ohmyksh got:(master)$ k wip
13 |   qbit@tal[0]:/usr/ports/openbsd-wip got:(master) git:(master)$ 
14 | #+end_src
15 | 
16 | *** Storing locations for later jumping
17 | 
18 | #+begin_src shell
19 |   cd ~/directory/with/long/name
20 |   k
21 | #+end_src
22 | 
23 |  After running ~k~, the current directory will be stored in ~~/.k~.
24 | 
25 |  From this point on, you can reach the directory from anywhere by running ~k
26 |  long name~.
27 | 
28 | *** Removing locations from jump list
29 | 
30 | #+begin_src shell
31 |   k long name
32 |   k rm
33 | #+end_src
34 | 
35 | *** Listing jumpable directories
36 | 
37 | #+begin_src shell
38 |   k ls
39 | #+end_src
40 | 
41 | *** Sorting / removing duplicates
42 | 
43 | #+begin_src shell
44 |   k clean
45 | #+end_src
46 | 


--------------------------------------------------------------------------------
/extensions/keychain.ksh:
--------------------------------------------------------------------------------
1 | KEYCHAIN_OPTS=${KEYCHAIN_OPTS:---gpg2 --inherit any --agents ssh,gpg -q -Q}
2 | KEYCHAIN_CONF="$HOME/.keychain/$(uname -n)-sh"
3 | 
4 | keychain ${KEYCHAIN_OPTS}
5 | 
6 | [ -f "${KEYCHAIN_CONF}" ] && . "${KEYCHAIN_CONF}"
7 | [ -f "${KEYCHAIN_CONF}-gpg" ] && . "${KEYCHAIN_CONF}-gpg"
8 | 
9 | 


--------------------------------------------------------------------------------
/extensions/keychain.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Extensions: keychain
 2 | 
 3 | The ~keychain~ gives you a convenient place to auto-start / load your various
 4 | agents (ssh, gpg).
 5 | 
 6 | ** Variables
 7 | 
 8 | | Option        | Default                                     |
 9 | |---------------+---------------------------------------------|
10 | | KEYCHAIN_OPTS | --gpg2 --inherit any --agents ssh,gpg -q -Q |
11 | 
12 | 


--------------------------------------------------------------------------------
/extensions/nocolor.ksh:
--------------------------------------------------------------------------------
 1 | # For a comprehensive list of no-color switches: https://no-color.org/
 2 | 
 3 | export NO_COLOR=1
 4 | 
 5 | export ANSIBLE_NOCOLOR=true
 6 | export DCC_COLORS=
 7 | 
 8 | # Ruby
 9 | export RUBY_TESTOPTS=--color=never
10 | export SPEC_OPTS=--no-color
11 | 
12 | alias ag='ag --nocolor'
13 | alias fzf='fzf --color=bw'
14 | alias hg='hg --color=never'
15 | alias lynx='lynx -nocolor'
16 | 


--------------------------------------------------------------------------------
/extensions/nocolor.org:
--------------------------------------------------------------------------------
1 | #+TITLE: Extensions: nocolor
2 | 
3 | ** nocolor
4 | 
5 | This extension attempts to disable terminal color for known programs /
6 | libraries. [[https://no-color.org/][no-color]] was used as a guide!
7 | 
8 | 
9 | 


--------------------------------------------------------------------------------
/extensions/openbsd.ksh:
--------------------------------------------------------------------------------
 1 | src() {
 2 | 	cd /usr/src/*/$1 || return
 3 | }
 4 | 
 5 | port() {
 6 | 	cd /usr/ports/*/$1 2>/dev/null || \
 7 | 		cd /usr/ports/*/*/$1 2>/dev/null || \
 8 | 		return
 9 | }
10 | 
11 | port_grep() {
12 | 	local _usage
13 | 	_usage="port_grep [file] [pattern]"
14 | 	[ -z $1 ] || [ -z $2 ] && echo $_usage
15 | 	[ ! -z $1 ] && [ ! -z $2 ] && find /usr/ports -iname "${1}" -exec grep -iH ${2} {} \;
16 | }
17 | 
18 | pclean() {
19 | 	find . -name \*.orig -exec rm {} \;
20 | 	find . -size 0 -exec rm {} \;
21 | }
22 | 
23 | revert_diffs() {
24 | 	for i in $(find . -name \*.orig); do
25 | 		F=$(echo $i | sed 's/\.orig//')
26 | 		mv -v "$i" "$F"
27 | 	done
28 | }
29 | 
30 | cdw() {
31 | 	cd $(make show=WRKSRC)
32 | }
33 | 
34 | maintains() {
35 | 	(
36 | 		cd /usr/ports/*/$1 > /dev/null 2>&1 && \
37 | 			make show=MAINTAINER || \
38 | 			echo "No port '/usr/ports/*/$1'"
39 | 	)
40 | }
41 | 
42 | seq() {
43 | 	start=$1
44 | 	end=$2
45 | 	if echo "$start" | egrep -q '^[0-9]+$'; then
46 | 		if [ "$start" -lt "$end" ]; then
47 | 			while [ $start -le "${end}" ]; do
48 | 				printf "%d\\n" "$start"
49 | 				start=$((start + 1))
50 | 			done
51 | 		else
52 | 			while [ $start -ge "${end}" ]; do
53 | 				printf "%d\\n" "$start"
54 | 				start=$((start - 1))
55 | 			done
56 | 		fi
57 | 	else
58 | 		start=$(printf "%d" \'$start)
59 | 		end=$(printf "%d" \'$end)
60 | 		if [ "$start" -lt "$end" ]; then
61 | 			while [ $start -le "${end}" ]; do
62 | 				printf "\x$(printf %x $start)\\n"
63 | 				start=$((start + 1))
64 | 			done
65 | 		else
66 | 			while [ $start -ge "${end}" ]; do
67 | 				printf "\x$(printf %x $start)\\n"
68 | 				start=$((start - 1))
69 | 			done
70 | 		fi
71 | 	fi
72 | }
73 | 


--------------------------------------------------------------------------------
/extensions/openbsd.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Extensions: openbsd
 2 | 
 3 | ** About
 4 | 
 5 | This extension adds a number of useful OpenBSD specific tools.
 6 | 
 7 | The following functions are added:
 8 | 
 9 | | Name           | Purpose                                                                                             |
10 | |----------------+-----------------------------------------------------------------------------------------------------|
11 | | cdw()          | Intended to be used from a port directory. Will change directory to ~$WRKSRC~.                      |
12 | | maintains()    | Similar to ~port()~, this will display the ~$MAINTAINER~ of a port passed in as the first argument. |
13 | | pclean()       | Remove ~.orig~ and empty files from ~$CWD~.                                                         |
14 | | revert_diffs() | Recursively move .orig files to their corresponding file name.                                      |
15 | | port()         | Like ~src()~, but for ~/usr/ports~.                                                                 |
16 | | port_grep()    | Recursively search ports tree for [file]'s that contain [pattern].                                  |
17 | | seq()          | A shell implementation of Linux's [[https://linux.die.net/man/1/seq][seq(1)]] command. It supports alpha and numeric ranges.             |
18 | | src()          | Similar to plan9's [[http://man.9front.org/1/src][src(1)]] command. It drops you to ~/usr/src/*/~.                            |
19 | 
20 | 


--------------------------------------------------------------------------------
/extensions/pkgup.ksh:
--------------------------------------------------------------------------------
 1 | #!/bin/ksh
 2 | 
 3 | pkgup() {
 4 | 	local _up_url
 5 | 	_up_url="${OHMY_PKGUP_URL:-https://pintobyte.com/pkgup/}"
 6 | 	[ ! -z $1 ] && _up_url=$1
 7 | 
 8 | 	if which obsdpkgup >/dev/null 2>&1; then
 9 | 		PKGUP_URL="$_up_url" obsdpkgup
10 | 	else
11 | 		echo "Please install obsdpkgup:"
12 | 		echo "  GO111MODULE=on go get -u github.com/neutralinsomniac/obsdpkgup"
13 | 	fi
14 | }
15 | 


--------------------------------------------------------------------------------
/extensions/pkgup.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Extensions: pkgup
 2 | ** About
 3 | 
 4 | ~pkgup~ uses [[https://github.com/neutralinsomniac/obsdpkgup][obsdpkgup]] to provide [[https://man.openbsd.org/pkg_add][~pkg_add~]] a shortened list of packages that need
 5 | updating. For more information on how this works, see ~obsdpkgup~'s
 6 | [[https://github.com/neutralinsomniac/obsdpkgup#rationale][documentation]].
 7 | 
 8 | | Function | Description                                                             |
 9 | |----------+-------------------------------------------------------------------------|
10 | | ~pkgup~  | Convenience function intended to have its result piped to ~pkg_add(1)~. |
11 | 


--------------------------------------------------------------------------------
/lib/loader.ksh:
--------------------------------------------------------------------------------
 1 | #!/bin/ksh
 2 | 
 3 | _loaded() {
 4 | 	${DEBUG}
 5 | 	local _val=$1 _set
 6 | 
 7 | 	shift
 8 | 	for _set; do
 9 | 		[[ $_val == "$_set" ]] && return 0
10 | 	done
11 | 	return 1
12 | }
13 | 
14 | load() {
15 | 	local _e=$1
16 | 	[[ -f $_e ]] && \
17 | 		. $_e
18 | }
19 | 
20 | load_extension() {
21 | 	${LOAD_EXTENSION_DEBUG}
22 | 	local _ext=$1 _l=${#extensions[@]} _n
23 | 	if ! _loaded "$_ext" "${extensions[@]}"; then
24 | 		${LOAD_EXTENSION_DEBUG}
25 | 
26 | 		((_n=_l+1))
27 | 
28 | 		extensions[$_n]=$_ext	
29 | 		load ${LOAD_PATH}/extensions/${_ext}.ksh
30 | 	else
31 | 		echo "Warning: extension '$_ext' already loaded"
32 | 	fi
33 | }
34 | 
35 | load_completion() {
36 | 	${LOAD_COMPLETION_DEBUG}
37 | 	local _comp=$1 _l=${#completions[@]} _n
38 | 	if ! _loaded "$_comp" "${completions[@]}"; then
39 | 		${LOAD_COMPLETION_DEBUG}
40 | 
41 | 		((_n=_l+1))
42 | 
43 | 		completions[$_n]=$_comp	
44 | 		load ${LOAD_PATH}/completions/${_comp}.ksh
45 | 	else
46 | 		echo "Warning: completion '$_comp' already loaded"
47 | 	fi
48 | }
49 | 
50 | set_prompt() {
51 | 	${PROMPT_DEBUG}
52 | 	local _prmpt=$1
53 | 
54 | 	load ${LOAD_PATH}/prompts/${_prmpt}.ksh
55 | }
56 | 
57 | paths() {
58 | 	${PATHS_DEBUG}
59 | 	local _path_list="$@"
60 | 	for p in ${_path_list[@]}; do
61 | 		${PATHS_DEBUG}
62 | 		[[ -d "${p}" ]] && PATH="${PATH}:$p"
63 | 	done
64 | 	export PATH
65 | }
66 | 
67 | reload_completions() {
68 | 	for _comp in ${completions[@]}; do
69 | 		load ${LOAD_PATH}/completions/${_comp}.ksh
70 | 	done
71 | }
72 | 
73 | reload_extensions() {
74 | 	for _ext in ${extensions[@]}; do
75 | 		load ${LOAD_PATH}/extensions/${_ext}.ksh
76 | 	done
77 | }
78 | 
79 | reload() {
80 | 	reload_completions
81 | 	reload_extensions
82 | }
83 | 


--------------------------------------------------------------------------------
/ohmy.ksh:
--------------------------------------------------------------------------------
 1 | #!/bin/ksh
 2 | 
 3 | #${DEBUG}
 4 | 
 5 | OHMY_DO=${OHMY_DO:-doas}
 6 | 
 7 | # Stub our load functions
 8 | paths() {
 9 | 	return 0
10 | }
11 | 
12 | load_extension() {
13 | 	return 0
14 | }
15 | 
16 | load_completion() {
17 | 	return 0
18 | }
19 | 
20 | set_prompt() {
21 | 	return 0
22 | }
23 | 
24 | if [ -z $OHMYKSH_DIR ]; then
25 | 	echo "Please set OHMYKSH_DIR to the location of ohmyksh"
26 | else
27 | 	LOAD_PATH="$OHMYKSH_DIR"
28 | 
29 | 	. ${LOAD_PATH}/lib/loader.ksh
30 | 
31 | 	set -A completions --
32 | 	set -A extensions --
33 | fi
34 | 


--------------------------------------------------------------------------------
/prompts/9.ksh:
--------------------------------------------------------------------------------
1 | PS1='% '
2 | 
3 | export PS1
4 | 


--------------------------------------------------------------------------------
/prompts/9.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Prompts: 9
 2 | 
 3 | ** An homage to plan9
 4 | 
 5 | If you have ever used ~rc~ on plan9 or from plan9port, you will recognize this
 6 | prompt!
 7 | 
 8 | Extremely minimal:
 9 | 
10 | #+begin_src shell
11 |   % uname -a
12 |   OpenBSD tal.tapenet.org 6.9 GENERIC.MP#394 amd64
13 |   % uptime
14 |    1:34PM  up  5:36, 1 user, load averages: 0.27, 0.21, 0.19
15 |   % 
16 | #+end_src
17 | 


--------------------------------------------------------------------------------
/prompts/og-openbsd.ksh:
--------------------------------------------------------------------------------
1 | PS1='\$ '
2 | 
3 | export PS1
4 | 


--------------------------------------------------------------------------------
/prompts/og-openbsd.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Prompts: og-openbsd
 2 | 
 3 | ** Blast from the past
 4 | 
 5 | Back in the day OpenBSD's default ksh prompt was simply: ~$ ~! For root it was
 6 | ~# ~.
 7 | 
 8 | #+begin_src shell
 9 |   $ uname -a
10 |   OpenBSD tal.tapenet.org 6.9 GENERIC.MP#394 amd64
11 |   $ uptime
12 |    1:35PM  up  5:38, 1 user, load averages: 0.32, 0.21, 0.19
13 |   $ 
14 | #+end_src
15 | 


--------------------------------------------------------------------------------
/prompts/plain.ksh:
--------------------------------------------------------------------------------
1 | PS1="\\h:\\w\\$ "
2 | 
3 | export PS1
4 | 


--------------------------------------------------------------------------------
/prompts/plain.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Prompts: plain
 2 | 
 3 | ** OpenBSD's prompt with a cherry on top
 4 | 
 5 | #+begin_src shell
 6 |   tal:~$ uname -a
 7 |   OpenBSD tal.tapenet.org 6.9 GENERIC.MP#394 amd64
 8 |   tal:~$ uptime
 9 |    1:37PM  up  5:39, 1 user, load averages: 0.08, 0.16, 0.16
10 |   tal:~$ 
11 | #+end_src
12 | 


--------------------------------------------------------------------------------
/prompts/q.ksh:
--------------------------------------------------------------------------------
1 | load_extension git-prompt
2 | load_extension got
3 | 
4 | PS1='\u@\h[\[\e[01;$(($??31:39))m\]$?\[\e[0m]\]:\w\]$(__got_ps1 " got:(%s)")$(__git_ps1 " git:(%s)")\$ '
5 | 
6 | export PS1
7 | 


--------------------------------------------------------------------------------
/prompts/q.org:
--------------------------------------------------------------------------------
 1 | #+TITLE: Prompts: q
 2 | 
 3 | ** My personal daily driver
 4 | 
 5 | I have been using variations of this prompt for as long as I can remember.
 6 | 
 7 | #+begin_src shell
 8 |   qbit@tal[0]:~$ uname -a
 9 |   OpenBSD tal.tapenet.org 6.9 GENERIC.MP#394 amd64
10 |   qbit@tal[0]:~$ uptime 
11 |    1:40PM  up  5:42, 1 user, load averages: 0.14, 0.14, 0.15
12 |   qbit@tal[0]:~$ cd src/ohmyksh
13 |   qbit@tal[0]:~/src/ohmyksh got:(master)$ cd /usr/ports/openbsd-wip
14 |   qbit@tal[0]:/usr/ports/openbsd-wip got:(master) git:(master)$ cd -
15 |   /home/qbit/src/ohmyksh
16 |   qbit@tal[0]:~/src/ohmyksh got:(master)$ invalidcommand
17 |   ksh: invalidcommand: not found
18 |   qbit@tal[127]:~/src/ohmyksh got:(master)$ 
19 | #+end_src
20 | 


--------------------------------------------------------------------------------