aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown2
-rwxr-xr-xbin/vis75
-rw-r--r--man/man1/vis.116
3 files changed, 93 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index e2a6c13c..7c2cd12c 100644
--- a/README.markdown
+++ b/README.markdown
@@ -279,6 +279,8 @@ Scripts
* `sue(8)` execs `sudoedit(8)` as the owner of all the file arguments given,
perhaps in cases where you may not necessarily have `root` `sudo(8)`
privileges.
+* `vis(1)` edits executable script files in `VISPATH`, defaulting to
+ `~/.local/bin`, for personal scripting snippets.
If you want to use the manuals, you may need to add `~/.local/share/man` to
your `/etc/manpath` configuration, depending on your system.
diff --git a/bin/vis b/bin/vis
new file mode 100755
index 00000000..8b0ddd57
--- /dev/null
+++ b/bin/vis
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+
+#
+# vis(1) -- Create and edit executable scripts in a directory VISPATH (defaults
+# to ~/.local/bin).
+#
+# Author: Tom Ryder
+# Copyright: 2015
+# License: Public domain
+#
+
+# Name self
+self=vis
+
+# Define a function to show usage
+usage() {
+ printf '%s: usage: %s [EDITOR_OPTS] [--] FILE1 [FILE2...]\n' \
+ "$self" "$self"
+}
+
+# Process options, including detecting requests for help
+declare -a opts
+for arg ; do
+ case $arg in
+ --help|-h|-\?)
+ usage
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ shift
+ opts=("${opts[@]}" "$arg")
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+# If no arguments left, spit usage as an error and bail
+if ! (($#)) ; then
+ usage >&2
+ exit 1
+fi
+
+# Create the script directory if it doesn't exist yet
+vispath=${VISPATH:-$HOME/.local/bin}
+if [[ ! -d $vispath ]] ; then
+ mkdir -p -- "$vispath" || exit
+fi
+
+# Create a new array with the script directory prepended to the given names
+declare -a files
+files=("${@/#/$vispath/}")
+
+# Collect the names of any scripts that don't exist yet so we can make them
+# executable after we're done editing
+declare -a creations
+for file in "${files[@]}" ; do
+ [[ -e $file ]] && continue
+ creations=("${creations[@]}" "$file")
+done
+
+# Run the editor; if EDITOR isn't set, use vi(1)
+"${EDITOR:-vi}" "${opts[@]}" -- "${files[@]}"
+
+# Make any created scripts executable if they now appear to be files
+for creation in "${creations[@]}" ; do
+ [[ -f $creation ]] || continue
+ chmod +x -- "$creation"
+done
+
diff --git a/man/man1/vis.1 b/man/man1/vis.1
new file mode 100644
index 00000000..fe9f340b
--- /dev/null
+++ b/man/man1/vis.1
@@ -0,0 +1,16 @@
+.TH VIS 1 "November 2015" "Manual page for vis"
+.SH NAME
+.B vis
+\- run vis(1) over multiple files
+.SH SYNOPSIS
+.B vis [EDITOR_OPTS] [--] FILE1 [FILE2...]
+.SH DESCRIPTION
+Create and edit executable scripts in a directory VISPATH (defaults to
+~/.local/bin). Makes any created files executable for convenience.
+.P
+ $ vis myscript
+ $ vis myscript newscript
+ $ EDITOR=vim vis -O tabone tabtwo
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
+