-
-
Save DanielTillett/d3d6b064805f5929adf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
# POSIX shell script equivalent of: | |
# <https://github.com/mplewis/shed> | |
# | |
# Usage: shed [SHELL_ARGUMENTS...] | |
# | |
# Executes stdin after you edit it. | |
# If $EDITOR is unset, uses $PAGER. | |
# If $PAGER is unset, uses cat(1). | |
# | |
# To execute stdin with OTHER shell: | |
# | |
# ln -s shed OTHERed | |
# ln -s shed fished # fish shell | |
# ln -s shed bashed # bash shell | |
# ln -s shed zshed # zsh shell | |
# ln -s shed kshed # ksh shell | |
# ln -s shed cshed # csh shell | |
# | |
# Written in 2015 by Suraj N. Kurapati <https://github.com/sunaku> | |
# write stdin to a temporary file | |
temp=$(mktemp) | |
trap "rm -f $temp" EXIT | |
trap 'exit' TERM INT | |
cat > $temp | |
exec 0</dev/tty | |
# edit or view the temporary file | |
${EDITOR:-${PAGER:-cat}} $temp | |
# confirm temporary file execution | |
echo -n 'Do you still want to execute this script? (yes/no): ' | |
until read REPLY && echo "$REPLY" | grep -iq '^yes$'; do | |
echo "$REPLY" | grep -iq '^no$' && exit | |
echo -n 'Please respond with either "yes" or "no": ' | |
done | |
# execute the temporary file | |
shell=$(basename "$0") | |
${shell%ed} "$@" $temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment