diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-10 13:31:03 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-10 13:31:03 +1200 |
commit | 835a273f0a708b5ef8c59e299b034c78b045d936 (patch) | |
tree | 95ca4e81eeb9571a301fa91c5af07940710f6739 /pdksh | |
parent | Merge branch 'master' into openbsd (diff) | |
download | dotfiles-835a273f0a708b5ef8c59e299b034c78b045d936.tar.gz dotfiles-835a273f0a708b5ef8c59e299b034c78b045d936.zip |
Port easy bashrc.d scripts to pdkshrc.d
Have left out anything that requires non-trivial fixes, mostly due to
variable scope or missing features.
Diffstat (limited to 'pdksh')
-rw-r--r-- | pdksh/pdkshrc.d/diff.pdksh | 4 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/ed.pdksh | 26 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/gdb.pdksh | 4 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/gpg.pdksh | 10 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/keychain.pdksh | 4 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/mkcd.pdksh | 4 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/pwgen.pdksh | 8 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/rcsdiff.pdksh | 4 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/scp.pdksh | 9 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/scr.pdksh | 11 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/sudo.pdksh | 7 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/tmux.pdksh | 19 | ||||
-rw-r--r-- | pdksh/pdkshrc.d/vim.pdksh | 15 |
13 files changed, 125 insertions, 0 deletions
diff --git a/pdksh/pdkshrc.d/diff.pdksh b/pdksh/pdkshrc.d/diff.pdksh new file mode 100644 index 00000000..2c752c8d --- /dev/null +++ b/pdksh/pdkshrc.d/diff.pdksh @@ -0,0 +1,4 @@ +# Use a unified format for diff(1) by default +diff() { + command diff -u "$@" +} diff --git a/pdksh/pdkshrc.d/ed.pdksh b/pdksh/pdkshrc.d/ed.pdksh new file mode 100644 index 00000000..f64f6dc6 --- /dev/null +++ b/pdksh/pdkshrc.d/ed.pdksh @@ -0,0 +1,26 @@ +# Add a colon prompt to ed when a command is expected rather than text; makes +# it feel a lot more like using ex. Only do this when stdin is a terminal, +# however. Also try and use -v for more verbose error output, and rlwrap(1) if +# it's available. +ed() { + + # We're only adding options if input is from a terminal + if [[ -t 0 ]] ; then + + # Colon prompt (POSIX) + set -- -p : "$@" + + # Verbose if availble (not POSIX) + if ed -sv - </dev/null >&0 2>&0 ; then + set -- -v "$@" + fi + fi + + # Execute the ed(1) call, in a wrapper if appropriate and with the + # concluded options + if [[ -t 0 ]] && command -v rlwrap >/dev/null ; then + command rlwrap ed "$@" + else + command ed "$@" + fi +} diff --git a/pdksh/pdkshrc.d/gdb.pdksh b/pdksh/pdkshrc.d/gdb.pdksh new file mode 100644 index 00000000..ec9d4137 --- /dev/null +++ b/pdksh/pdkshrc.d/gdb.pdksh @@ -0,0 +1,4 @@ +# Don't print the GDB copyright message on every invocation +gdb() { + command gdb -q "$@" +} diff --git a/pdksh/pdkshrc.d/gpg.pdksh b/pdksh/pdkshrc.d/gpg.pdksh new file mode 100644 index 00000000..62d123ea --- /dev/null +++ b/pdksh/pdkshrc.d/gpg.pdksh @@ -0,0 +1,10 @@ +# Wrapper around gpg(1) to stop ``--batch'' breaking things +gpg() { + # shellcheck disable=SC2048 + case $* in + *--ed*|*--gen-k*|*--sign-k*) + set -- --no-batch "$@" + ;; + esac + command gpg "$@" +} diff --git a/pdksh/pdkshrc.d/keychain.pdksh b/pdksh/pdkshrc.d/keychain.pdksh new file mode 100644 index 00000000..40fe5d71 --- /dev/null +++ b/pdksh/pdkshrc.d/keychain.pdksh @@ -0,0 +1,4 @@ +# If GPG_TTY is set, update it +if [[ -n $GPG_TTY ]] ; then + GPG_TTY=$(tty) +fi diff --git a/pdksh/pdkshrc.d/mkcd.pdksh b/pdksh/pdkshrc.d/mkcd.pdksh new file mode 100644 index 00000000..6342d4a6 --- /dev/null +++ b/pdksh/pdkshrc.d/mkcd.pdksh @@ -0,0 +1,4 @@ +# Create a directory and change into it +mkcd() { + mkdir -p -- "$1" && builtin cd -- "$1" +} diff --git a/pdksh/pdkshrc.d/pwgen.pdksh b/pdksh/pdkshrc.d/pwgen.pdksh new file mode 100644 index 00000000..7ba056e5 --- /dev/null +++ b/pdksh/pdkshrc.d/pwgen.pdksh @@ -0,0 +1,8 @@ +# Set some defaults for pwgen(1), because its defaults are to give me a long +# list of relatively short passwords, when I generally want only one good one +pwgen() { + if ! (($#)) ; then + set -- --secure -- "${PWGEN_LENGTH:-15}" "${PWGEN_COUNT:-1}" + fi + command pwgen "$@" +} diff --git a/pdksh/pdkshrc.d/rcsdiff.pdksh b/pdksh/pdkshrc.d/rcsdiff.pdksh new file mode 100644 index 00000000..18b1d324 --- /dev/null +++ b/pdksh/pdkshrc.d/rcsdiff.pdksh @@ -0,0 +1,4 @@ +# Use a unified format for rcsdiff(1) by default +rcsdiff() { + command rcsdiff -u "$@" +} diff --git a/pdksh/pdkshrc.d/scp.pdksh b/pdksh/pdkshrc.d/scp.pdksh new file mode 100644 index 00000000..c3565f21 --- /dev/null +++ b/pdksh/pdkshrc.d/scp.pdksh @@ -0,0 +1,9 @@ +# Wrap scp(1) to check for missing colons +scp() { + # shellcheck disable=SC2048 + if (($# >= 2)) && [[ $* != *:* ]] ; then + printf 'ksh: scp: Missing colon, probably an error\n' >&2 + return 2 + fi + command scp "$@" +} diff --git a/pdksh/pdkshrc.d/scr.pdksh b/pdksh/pdkshrc.d/scr.pdksh new file mode 100644 index 00000000..01bd20cb --- /dev/null +++ b/pdksh/pdkshrc.d/scr.pdksh @@ -0,0 +1,11 @@ +# Create a temporary directory and change into it, to stop me putting stray +# files into $HOME, and making the system do cleanup for me. Single optional +# argument is the string to use for naming the directory; defaults to "scr". +scr() { + if (($# <= 1)) ; then + cd -- "$(mktd "${1:-scr}")" + else + printf 'ksh: scr: too many arguments\n' >&2 + return 2 + fi +} diff --git a/pdksh/pdkshrc.d/sudo.pdksh b/pdksh/pdkshrc.d/sudo.pdksh new file mode 100644 index 00000000..d6d91d12 --- /dev/null +++ b/pdksh/pdkshrc.d/sudo.pdksh @@ -0,0 +1,7 @@ +# Add the -H parameter to sudo(8) calls, always use the target user's $HOME +sudo() { + if [[ $1 != -v ]] ; then + set -- -H "$@" + fi + command sudo "$@" +} diff --git a/pdksh/pdkshrc.d/tmux.pdksh b/pdksh/pdkshrc.d/tmux.pdksh new file mode 100644 index 00000000..f0d0e36a --- /dev/null +++ b/pdksh/pdkshrc.d/tmux.pdksh @@ -0,0 +1,19 @@ +# Attach to existing tmux session rather than create a new one if possible +tmux() { + + # If given any arguments, just use them as they are + if (($#)) ; then + : + + # If a session exists, just attach to it + elif command tmux has-session 2>/dev/null ; then + set -- attach-session -d + + # Create a new session with an appropriate name + else + set -- new-session -s "${TMUX_SESSION:-default}" + fi + + # Execute with concluded arguments + command tmux "$@" +} diff --git a/pdksh/pdkshrc.d/vim.pdksh b/pdksh/pdkshrc.d/vim.pdksh new file mode 100644 index 00000000..37fc1871 --- /dev/null +++ b/pdksh/pdkshrc.d/vim.pdksh @@ -0,0 +1,15 @@ +# If Vim exists on the system, use it instead of ex, vi, and view +if ! hash vim 2>/dev/null ; then + return +fi + +# Define functions proper +ex() { + vim -e "$@" +} +vi() { + vim "$@" +} +view() { + vim -R "$@" +} |