I've got this code:
(defun insert-random-uuid ()
(interactive)
(shell-command "uuidgen" t))
which produces a uuid that looks like this ffc715d2-1e10-4faf-b1f6-f85cae88a7d7
. However, I believe it's throwing in a newline and that it isn't returning a string:
(stringp (insert-random-uuid))
which returns nil
So I find this at the EmacsWiki:
(defun chomp (str)
"Chomp leading and tailing whitespace from STR."
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"
str)
(setq str (replace-match "" t t str)))
str)
which seems to handle both whitespace and \n. But of course (chomp (insert-random-uuid)
gives an error, no doubt because insert-random-uuid
is not returning a true string. So what is it returning, and how can I remove the newline? I tried various things to "cast" the output to string, but no luck. How can I get rid of this newline?
shell-command-to-string
.