Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active June 26, 2019 23:56
Show Gist options
  • Save jayers99/39bb45c1109e3b5c128479c89c7b0538 to your computer and use it in GitHub Desktop.
Save jayers99/39bb45c1109e3b5c128479c89c7b0538 to your computer and use it in GitHub Desktop.
copy the last command to a file
snipit() {
[ ! -z "${1}" ] && snip_file="${1}" || snip_file='snippets.sh'
echo "" >> $snip_file
read -p "Enter comment: " comment
[ ! -z "${comment}" ] && echo "# ${comment}" >> $snip_file
fc -ln -1 | sed '1s/^[[:space:]]*//' >> $snip_file
[ ! -z "${comment}" ] && tail -n 2 $snip_file || tail -n 1 $snip_file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment