set -x: tab completion results in messy output when working in debug mode

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I understand that set -x gets a Bash user into debug mode and I feel that working full time in debug mode will help me handle possible problems better in Bash.



I experience a problem when working with set -x:



When I try to use the native tab completion of my distro (Ubuntu 16.04) to complete a directory's name, I get a very long, messy output.



For example, $PWD is /var/www/html/ and I run either of these:



cd ~/u[tab completion to complete u to ulcwe]



cd ~ && cd u[tab completion to complete u to ulcwe]



In both examples I'll get a very long and messy output:



+ return 0
+ local -a toks
+ local quoted x tmp
+ _quote_readline_by_ref '~/u' quoted
+ '[' -z '~/u' ']'
+ [[ ~/u == '* ]]
+ [[ ~/u == ~* ]]
+ printf -v quoted '~%q' /u
+ [[ ~/u == *\* ]]
+ [[ ~/u == $* ]]
++ compgen -d -- '~/u'
+ x='~/ulcwe'
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ [[ -d != -d ]]
+ [[ -n '' ]]
+ [[ 1 -ne 0 ]]
+ compopt -o filenames
+ COMPREPLY+=("$toks[@]")
+ return 0
lcwe/


Note the lcwe in the end.



The above output is just part of a much larger output.



How could I keep working in debug mode full time (set -x) but without all that output when performing tab completion?







share|improve this question


























    up vote
    3
    down vote

    favorite












    I understand that set -x gets a Bash user into debug mode and I feel that working full time in debug mode will help me handle possible problems better in Bash.



    I experience a problem when working with set -x:



    When I try to use the native tab completion of my distro (Ubuntu 16.04) to complete a directory's name, I get a very long, messy output.



    For example, $PWD is /var/www/html/ and I run either of these:



    cd ~/u[tab completion to complete u to ulcwe]



    cd ~ && cd u[tab completion to complete u to ulcwe]



    In both examples I'll get a very long and messy output:



    + return 0
    + local -a toks
    + local quoted x tmp
    + _quote_readline_by_ref '~/u' quoted
    + '[' -z '~/u' ']'
    + [[ ~/u == '* ]]
    + [[ ~/u == ~* ]]
    + printf -v quoted '~%q' /u
    + [[ ~/u == *\* ]]
    + [[ ~/u == $* ]]
    ++ compgen -d -- '~/u'
    + x='~/ulcwe'
    + read -r tmp
    + toks+=("$tmp")
    + read -r tmp
    + [[ -d != -d ]]
    + [[ -n '' ]]
    + [[ 1 -ne 0 ]]
    + compopt -o filenames
    + COMPREPLY+=("$toks[@]")
    + return 0
    lcwe/


    Note the lcwe in the end.



    The above output is just part of a much larger output.



    How could I keep working in debug mode full time (set -x) but without all that output when performing tab completion?







    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I understand that set -x gets a Bash user into debug mode and I feel that working full time in debug mode will help me handle possible problems better in Bash.



      I experience a problem when working with set -x:



      When I try to use the native tab completion of my distro (Ubuntu 16.04) to complete a directory's name, I get a very long, messy output.



      For example, $PWD is /var/www/html/ and I run either of these:



      cd ~/u[tab completion to complete u to ulcwe]



      cd ~ && cd u[tab completion to complete u to ulcwe]



      In both examples I'll get a very long and messy output:



      + return 0
      + local -a toks
      + local quoted x tmp
      + _quote_readline_by_ref '~/u' quoted
      + '[' -z '~/u' ']'
      + [[ ~/u == '* ]]
      + [[ ~/u == ~* ]]
      + printf -v quoted '~%q' /u
      + [[ ~/u == *\* ]]
      + [[ ~/u == $* ]]
      ++ compgen -d -- '~/u'
      + x='~/ulcwe'
      + read -r tmp
      + toks+=("$tmp")
      + read -r tmp
      + [[ -d != -d ]]
      + [[ -n '' ]]
      + [[ 1 -ne 0 ]]
      + compopt -o filenames
      + COMPREPLY+=("$toks[@]")
      + return 0
      lcwe/


      Note the lcwe in the end.



      The above output is just part of a much larger output.



      How could I keep working in debug mode full time (set -x) but without all that output when performing tab completion?







      share|improve this question














      I understand that set -x gets a Bash user into debug mode and I feel that working full time in debug mode will help me handle possible problems better in Bash.



      I experience a problem when working with set -x:



      When I try to use the native tab completion of my distro (Ubuntu 16.04) to complete a directory's name, I get a very long, messy output.



      For example, $PWD is /var/www/html/ and I run either of these:



      cd ~/u[tab completion to complete u to ulcwe]



      cd ~ && cd u[tab completion to complete u to ulcwe]



      In both examples I'll get a very long and messy output:



      + return 0
      + local -a toks
      + local quoted x tmp
      + _quote_readline_by_ref '~/u' quoted
      + '[' -z '~/u' ']'
      + [[ ~/u == '* ]]
      + [[ ~/u == ~* ]]
      + printf -v quoted '~%q' /u
      + [[ ~/u == *\* ]]
      + [[ ~/u == $* ]]
      ++ compgen -d -- '~/u'
      + x='~/ulcwe'
      + read -r tmp
      + toks+=("$tmp")
      + read -r tmp
      + [[ -d != -d ]]
      + [[ -n '' ]]
      + [[ 1 -ne 0 ]]
      + compopt -o filenames
      + COMPREPLY+=("$toks[@]")
      + return 0
      lcwe/


      Note the lcwe in the end.



      The above output is just part of a much larger output.



      How could I keep working in debug mode full time (set -x) but without all that output when performing tab completion?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 27 at 21:24

























      asked Feb 27 at 17:54









      user9303970

      123224




      123224




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          This is due to the programmable completion feature of the shell that you are using.



          If you're happy with basic tab completion for commands and filenames in bash, then running



          complete -r


          in your ~/.bashrc will remove any "fancy" (programmable) completion that involves calling functions etc. in the current shell's environment.



          Basic filename completion (like what you're doing in the examples in your question) will still work after turning off programmable completion.



          Programmable completion is available in some shells and allows one to hook up callback functions that examine the state of the command line etc. to figure out what the possible strings that the user might want to insert next might be. For example, typing ssh and then Space and Tab may invoke a function that parses your ~/.ssh/config file for possible hostnames to connect to, or typing git checkout and then Space and Tab may cause a function to run a git command to figure out what branches are available in the current repository.



          Some users rely on programmable completions for speed and/or productivity reasons, but yes, if you have set -x active in the interactive shell session, these actions would produce trace output in the terminal.




          I've never been a friend of programmable completion in any shell as I don't want a simple Tab press to do "magic behind my back" in all sorts of interesting ways. I also think it's a bit lazy, but that's definitely only my personal opinion.






          share|improve this answer






















          • Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
            – user9303970
            Feb 27 at 19:58










          • BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
            – user9303970
            Feb 27 at 22:22










          • @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
            – Kusalananda
            Feb 28 at 6:42










          • @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
            – Kusalananda
            Feb 28 at 6:47






          • 1




            Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
            – user9303970
            Mar 1 at 10:10










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426989%2fset-x-tab-completion-results-in-messy-output-when-working-in-debug-mode%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          This is due to the programmable completion feature of the shell that you are using.



          If you're happy with basic tab completion for commands and filenames in bash, then running



          complete -r


          in your ~/.bashrc will remove any "fancy" (programmable) completion that involves calling functions etc. in the current shell's environment.



          Basic filename completion (like what you're doing in the examples in your question) will still work after turning off programmable completion.



          Programmable completion is available in some shells and allows one to hook up callback functions that examine the state of the command line etc. to figure out what the possible strings that the user might want to insert next might be. For example, typing ssh and then Space and Tab may invoke a function that parses your ~/.ssh/config file for possible hostnames to connect to, or typing git checkout and then Space and Tab may cause a function to run a git command to figure out what branches are available in the current repository.



          Some users rely on programmable completions for speed and/or productivity reasons, but yes, if you have set -x active in the interactive shell session, these actions would produce trace output in the terminal.




          I've never been a friend of programmable completion in any shell as I don't want a simple Tab press to do "magic behind my back" in all sorts of interesting ways. I also think it's a bit lazy, but that's definitely only my personal opinion.






          share|improve this answer






















          • Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
            – user9303970
            Feb 27 at 19:58










          • BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
            – user9303970
            Feb 27 at 22:22










          • @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
            – Kusalananda
            Feb 28 at 6:42










          • @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
            – Kusalananda
            Feb 28 at 6:47






          • 1




            Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
            – user9303970
            Mar 1 at 10:10














          up vote
          2
          down vote



          accepted










          This is due to the programmable completion feature of the shell that you are using.



          If you're happy with basic tab completion for commands and filenames in bash, then running



          complete -r


          in your ~/.bashrc will remove any "fancy" (programmable) completion that involves calling functions etc. in the current shell's environment.



          Basic filename completion (like what you're doing in the examples in your question) will still work after turning off programmable completion.



          Programmable completion is available in some shells and allows one to hook up callback functions that examine the state of the command line etc. to figure out what the possible strings that the user might want to insert next might be. For example, typing ssh and then Space and Tab may invoke a function that parses your ~/.ssh/config file for possible hostnames to connect to, or typing git checkout and then Space and Tab may cause a function to run a git command to figure out what branches are available in the current repository.



          Some users rely on programmable completions for speed and/or productivity reasons, but yes, if you have set -x active in the interactive shell session, these actions would produce trace output in the terminal.




          I've never been a friend of programmable completion in any shell as I don't want a simple Tab press to do "magic behind my back" in all sorts of interesting ways. I also think it's a bit lazy, but that's definitely only my personal opinion.






          share|improve this answer






















          • Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
            – user9303970
            Feb 27 at 19:58










          • BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
            – user9303970
            Feb 27 at 22:22










          • @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
            – Kusalananda
            Feb 28 at 6:42










          • @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
            – Kusalananda
            Feb 28 at 6:47






          • 1




            Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
            – user9303970
            Mar 1 at 10:10












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          This is due to the programmable completion feature of the shell that you are using.



          If you're happy with basic tab completion for commands and filenames in bash, then running



          complete -r


          in your ~/.bashrc will remove any "fancy" (programmable) completion that involves calling functions etc. in the current shell's environment.



          Basic filename completion (like what you're doing in the examples in your question) will still work after turning off programmable completion.



          Programmable completion is available in some shells and allows one to hook up callback functions that examine the state of the command line etc. to figure out what the possible strings that the user might want to insert next might be. For example, typing ssh and then Space and Tab may invoke a function that parses your ~/.ssh/config file for possible hostnames to connect to, or typing git checkout and then Space and Tab may cause a function to run a git command to figure out what branches are available in the current repository.



          Some users rely on programmable completions for speed and/or productivity reasons, but yes, if you have set -x active in the interactive shell session, these actions would produce trace output in the terminal.




          I've never been a friend of programmable completion in any shell as I don't want a simple Tab press to do "magic behind my back" in all sorts of interesting ways. I also think it's a bit lazy, but that's definitely only my personal opinion.






          share|improve this answer














          This is due to the programmable completion feature of the shell that you are using.



          If you're happy with basic tab completion for commands and filenames in bash, then running



          complete -r


          in your ~/.bashrc will remove any "fancy" (programmable) completion that involves calling functions etc. in the current shell's environment.



          Basic filename completion (like what you're doing in the examples in your question) will still work after turning off programmable completion.



          Programmable completion is available in some shells and allows one to hook up callback functions that examine the state of the command line etc. to figure out what the possible strings that the user might want to insert next might be. For example, typing ssh and then Space and Tab may invoke a function that parses your ~/.ssh/config file for possible hostnames to connect to, or typing git checkout and then Space and Tab may cause a function to run a git command to figure out what branches are available in the current repository.



          Some users rely on programmable completions for speed and/or productivity reasons, but yes, if you have set -x active in the interactive shell session, these actions would produce trace output in the terminal.




          I've never been a friend of programmable completion in any shell as I don't want a simple Tab press to do "magic behind my back" in all sorts of interesting ways. I also think it's a bit lazy, but that's definitely only my personal opinion.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 28 at 6:49

























          answered Feb 27 at 18:02









          Kusalananda

          103k13202318




          103k13202318











          • Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
            – user9303970
            Feb 27 at 19:58










          • BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
            – user9303970
            Feb 27 at 22:22










          • @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
            – Kusalananda
            Feb 28 at 6:42










          • @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
            – Kusalananda
            Feb 28 at 6:47






          • 1




            Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
            – user9303970
            Mar 1 at 10:10
















          • Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
            – user9303970
            Feb 27 at 19:58










          • BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
            – user9303970
            Feb 27 at 22:22










          • @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
            – Kusalananda
            Feb 28 at 6:42










          • @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
            – Kusalananda
            Feb 28 at 6:47






          • 1




            Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
            – user9303970
            Mar 1 at 10:10















          Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
          – user9303970
          Feb 27 at 19:58




          Thx. I know what is a callback a function (a function that is called back by another function) but I don't know what do you mean by "hook up". Also dear Kusalananda, please add an opening statement similar to "The behavior you're witnessing does with programmable completion which is a feature of tab completion once could turn on or off". Thanks again!
          – user9303970
          Feb 27 at 19:58












          BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
          – user9303970
          Feb 27 at 22:22




          BTW, just for the sake of mentioning it if someone wants it: How do you revert complete -r? I tried complete +r and also reboot but in both cases no revert was done.
          – user9303970
          Feb 27 at 22:22












          @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
          – Kusalananda
          Feb 28 at 6:42




          @user9303970 The only way to revert the change is to start a new shell session that does not do complete -r. This would source the default shell startup files, some of which initializes the programmable completions.
          – Kusalananda
          Feb 28 at 6:42












          @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
          – Kusalananda
          Feb 28 at 6:47




          @user9303970 A callback function, in the general sense (it's used in other settings as well, with other programming languages, for example in some parsers etc.) is a user-defined function that you "install" or "hook up" or "register" with a system to be called under certain circumstances. A simple example, which i believe could be called a "callback function" is the comparison function used with the standard C library's qsort() routine. qsort() can sort any type of C structure, but needs help from a user-supplied comparison function to do the actual comparisons.
          – Kusalananda
          Feb 28 at 6:47




          1




          1




          Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
          – user9303970
          Mar 1 at 10:10




          Sorry Kusalanada, I misled myself and you. The reboot took me out of set -x hence I didn't see the programmable completion that came back with the new set -x mode. I will now put set -x && complete -r in ~/.bashrc and will have both of them working harmoniously. Sorry again, please forgive me for this. I should have think more on this.
          – user9303970
          Mar 1 at 10:10












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426989%2fset-x-tab-completion-results-in-messy-output-when-working-in-debug-mode%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)