I call git get the toplevel dir (according to Is there a way to get the git root directory in one command? ).
(let ((tmpbuffer (get-buffer-create (make-temp-name "git"))))
(call-process "git" nil tmpbuffer nil "rev-parse" "--show-toplevel")
(with-current-buffer tmpbuffer
(with-output-to-string
(princ (buffer-string))
(kill-buffer))))
But there's a trailing newline in the string returned. I'm not sure how to get rid of it.
Open TextPad and the file you want to edit. Click Search and then Replace. In the Replace window, in the Find what section, type ^\n (caret, backslash 'n') and leave the Replace with section blank, unless you want to replace a blank line with other text. Check the Regular Expression box.
Use the strip() Function to Remove a Newline Character From the String in Python. The strip() function is used to remove both trailing and leading newlines from the string that it is being operated on. It also removes the whitespaces on both sides of the string.
The fgets() function stores the result in string and adds a NULL character (\0) to the end of the string. The string includes the newline character, if read.
I think you can do
(replace-regexp-in-string "\n$" ""
(shell-command-to-string "git rev-parse --show-toplevel"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With