Last active
October 11, 2015 02:57
-
-
Save lionicsheriff/3791800 to your computer and use it in GitHub Desktop.
Push command into shell history
This file contains 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
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 \#"$@"; | |
} |
$ 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
$ history_push_commented echo "abcdef ghi" jkl
$ # echo 'abcdef ghi' jkl