aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ISSUES.markdown8
-rwxr-xr-xbin/eds75
2 files changed, 37 insertions, 46 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index b94ab582..a7b50808 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -8,14 +8,6 @@ Known issues
* man(1) completion doesn't work on OpenBSD as manpath(1) isn't a thing on
that system; need to find some way of finding which manual directories
should be searched at runtime, if there is one.
-* Where practical, the remaining Bash scripts in bin need to be reimplemented
- as POSIX sh
- - Mostly done now:
-
- [tom@conan:~/.dotfiles/bin](git:master)$ grep bash *
- eds:#!/usr/bin/env bash
- han:#!/usr/bin/env bash
-
* OpenBSD doesn't have a `pandoc` package at all. It would be nice to find
some way of converting the README.markdown into a palatable troff format
with some more readily available (and preferably less heavyweight) tool.
diff --git a/bin/eds b/bin/eds
index 2afd0a07..3d0fceed 100755
--- a/bin/eds
+++ b/bin/eds
@@ -1,53 +1,52 @@
-#!/usr/bin/env bash
+#!/bin/sh
# Create and edit executable scripts in a directory EDSPATH (defaults to ~/.local/bin)
-# Give up completely if no BASH_VERSINFO (<2.0)
-[ -n "$BASH_VERSINFO" ] || exit
-
-# Process options, including detecting requests for help
-declare -a opts
-for arg ; do
- case $arg in
- --)
- shift
- break
- ;;
- -*)
- shift
- opts[${#opts[@]}]=$arg
- ;;
- esac
-done
-
-# Need at least one file after options are parsed out
-if ! (($#)) ; then
+# Need at least one script name
+if [ "$#" -eq 0 ] ; then
printf >&2 'eds: Need at least one script name\n'
exit 2
fi
# Create the script directory if it doesn't exist yet
-edspath=${EDSPATH:-$HOME/.local/bin}
-if [[ ! -d $edspath ]] ; then
- mkdir -p -- "$edspath" || exit
+ep=${EDSPATH:-$HOME/.local/bin}
+if ! [ -d "$ep" ] ; then
+ mkdir -p -- "$ep" || exit
fi
-# Create a new array with the script directory prepended to the given names
-declare -a files
-files=("${@/#/"$edspath"/}")
+# Warn if that's not in $PATH
+case :$PATH: in
+ *:"$ep":*) ;;
+ *)
+ printf >&2 'eds: warning: %s not in PATH\n' "$ep"
+ ;;
+esac
-# 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
+# Prepend the path to each of the names given if they don't look like options
+for arg ; do
+ [ -n "$reset" ] || set -- && reset=1
+ case $arg in
+ --)
+ optend=1
+ set -- "$@" "$arg"
+ continue
+ ;;
+ -*)
+ if [ -z "$optend" ] ; then
+ set -- "$@" "$arg"
+ continue
+ fi
+ ;;
+ esac
+ optend=1
+ set -- "$@" "$ep"/"$arg"
done
-# Run the editor; if EDITOR isn't set, use ed(1)
-"${VISUAL:-"${EDITOR:-ed}"}" "${opts[@]}" -- "${files[@]}"
+# Run the editor over the arguments
+echo "${VISUAL:-"${EDITOR:-ed}"}" "$@"
+exit
# Make any created scripts executable if they now appear to be files
-for creation in "${creations[@]}" ; do
- [[ -f $creation ]] || continue
- chmod +x -- "$creation"
+for script ; do
+ [ -f "$script" ] || continue
+ chmod +x -- "$script"
done