0

Is there a utility I could install that will automatically remove ("sift") any tabulation indents from code blocks and heredocuments I paste into the Ubuntu CLI?

For example, if I paste:

    (
    command1
    command2
    )

Or

    cat <<-'PMA' > /opt/script.sh
    string1
    string2
    PMA

In pasting, these will become:

(
command1
command2
)

Or

cat <<-'PMA' > /opt/script.sh
string1
string2
PMA

To further clarify:

My aim is that between pasting to execution all leading tabulations (and maybe also spaces), will be deleted.

  • 1
    why though? Wordsplitting destroys extra whitespace anyway... it makes no difference to the command – Zanna May 1 '17 at 14:17
  • Something like this would work I guess: sed -i -e "s/^\s\{1,\}//g filename", here. – Ravexina May 1 '17 at 14:18
  • @Zanna, what you say is interesting --- In my machines it doesn't happen when I combine a cat heredoc inside the block. I believe that if you will try that in your PC when it includes a cat heredoc, you will notice execution break as well... – user423047 May 1 '17 at 14:59
  • oh I see what you mean, yes you are right – Zanna May 1 '17 at 15:08
0

Run bind -u complete, then Bash will behave exactly as you want: it will not allow you to input tabs.

Source: This answer on "Disable bash tab completion"

| improve this answer | |
  • But I don't want to destroy the whole tab completion. I want no tabs only in my specific codes. – user423047 May 3 '17 at 9:18
  • @Benia I don't think that's possible. Bash can't tell the difference between typing a character and pasting a character. – wjandrea May 3 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy