Skip to content

Instantly share code, notes, and snippets.

@lionicsheriff
Last active October 11, 2015 02:57
Show Gist options
  • Save lionicsheriff/3791800 to your computer and use it in GitHub Desktop.
Save lionicsheriff/3791800 to your computer and use it in GitHub Desktop.
Push command into shell history
history_push(){
local COMMAND
for arg in "$@"
do
case "$arg" in
*\ *)
*\'*)
COMMAND="$COMMAND \"$arg\""
;;
*\"*)
COMMAND="$COMMAND '$arg'"
;;
*)
COMMAND="$COMMAND \"$arg\""
;;
esac
;;
*)
if test -z "$COMMAND"
then
COMMAND="$arg"
else
COMMAND="$COMMAND $arg"
fi
;;
esac
done
history -s "$COMMAND"
}
history_push_commented(){
history_push \#"$@";
}
@lionicsheriff
Copy link
Author

$ history_push_commented echo "abcdef ghi" jkl

$ # echo 'abcdef ghi' jkl

@lionicsheriff
Copy link
Author

$ history_push echo "abc' def" ghi jkl 'mno "pqr stu" vwx'
$ echo "abc' def" ghi jkl 'mno "pqr stu" vwx'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment