Strip the leading dollar sign when copying shell command #35615
Replies: 4 comments 2 replies
-
There's actually a dedicated syntax for shell-sessions: ```console
$ echo Foo
Foo
``` The syntax highlighting being used even tokenises the prompt-symbol for the purposes of excluding it from copied code-snippets. However, GitHub have yet to make use of it... Note that ```console
# id -u
0
# # Comment 1
$ # Comment 2
``` |
Beta Was this translation helpful? Give feedback.
-
Thanks, I didn't know about I'll use it in my Markdowns so that I'll be ready when GitHub implements this feature. |
Beta Was this translation helpful? Give feedback.
-
Users can also solve this problem themselves via their own config. For example, Zsh users can create a dirt simple pass-thru dollar function like so: # .zshrc
function \$ { "$@"; } Bash users can't make a function called # .bashrc
ble/function#advice around ble/widget/default/accept-line '
if [[ "${_ble_edit_str:0:2}" == "$ " ]]; then
ble/widget/beginning-of-logical-line
ble/widget/insert-string "${_ble_edit_str:2}"
ble/widget/kill-forward-logical-line
fi
ble/function#advice/do
' And in Fish, you can add your own paste scrubber: function fish_paste_scrubber
# run the Fish default
fish_clipboard_paste
# remove any leading dollar signs from the pasted command
commandline -r (string replace -r '^\$ ' '' (commandline))
end Then you have to bind it to your paste key sequence in function fish_user_key_bindings
bind \cv fish_paste_scrubber
# ... other keybindings ...
end It'd still be a good idea to implement this feature. Just thought it worth mentioning this can be solved on the user end too. Since things like GitLab and BitBucket and blogs and articles etc exist, users will forever be annoyed by this problem if they don't apply a fix themselves. |
Beta Was this translation helpful? Give feedback.
-
Interesting I don't think that can be omitted, thought you can still just modify it in a way to make look prettier. |
Beta Was this translation helpful? Give feedback.
-
When writing READMEs (or basically any Markdown) I really like to prefix the commands that I want the reader to copy-paste into their terminal with a dollar sign
$
.For example, I prefer this:
to this:
Unfortunately, prefixing the commands with the dollar sign makes it harder for the reader to use the built-in Copy button that GitHub displays by default on the right side of the code snippet.
This often results in small, annoying mistakes:
I'd like the leading dollar sign to be automatically stripped when copying the snippet. Maybe it should happen only when the type of the code snippet is
bash
orsh
– I don't know.A site that already does this is Google's docs. See example here.
Beta Was this translation helpful? Give feedback.
All reactions