Bash completion functions for pmount and pumount

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
5
down vote

favorite












I found a problem with Debian's Bash-completion for pmount and pumount, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.



I'd like a review of this before sending my new functions with the bug report.



The original was in /etc/bash_completion.d/pmount, but the modern approach is to have two files in /usr/share/bash-completion/completions/ to support demand-loading of completion functions. We assume that the _init_completion is provided as part of this mechanism, to initialize shell variables cur and prev more usefully than the usual $2 and $3 (e.g. skipping redirection words).



I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/ to ensure I'm using the device/partition I'm expecting, for example).




/usr/share/bash-completion/completions/pmount



_pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
test "$#devices[@]" -gt 0 &&
complete -F _pmount pmount



/usr/share/bash-completion/completions/pumount



_pumount() 
# shellcheck disable=SC2034
local cur prev words cword
_init_completion &&
complete -F _pumount pumount



Some specific questions:



  • Should I be checking that commands such as modinfo actually exist? Which commands don't need checking? (I believe that grep and cut are in "Essential" packages, so can be assumed, but I'm less sure about readlink, for example).

  • Is it guaranteed that /media is the only place to find the mountpoints?

  • How can I make those long lines wrap nicely without becoming even less clear?

Obviously, any other observations or improvements are invited, too!







share|improve this question



























    up vote
    5
    down vote

    favorite












    I found a problem with Debian's Bash-completion for pmount and pumount, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.



    I'd like a review of this before sending my new functions with the bug report.



    The original was in /etc/bash_completion.d/pmount, but the modern approach is to have two files in /usr/share/bash-completion/completions/ to support demand-loading of completion functions. We assume that the _init_completion is provided as part of this mechanism, to initialize shell variables cur and prev more usefully than the usual $2 and $3 (e.g. skipping redirection words).



    I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/ to ensure I'm using the device/partition I'm expecting, for example).




    /usr/share/bash-completion/completions/pmount



    _pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
    test "$#devices[@]" -gt 0 &&
    complete -F _pmount pmount



    /usr/share/bash-completion/completions/pumount



    _pumount() 
    # shellcheck disable=SC2034
    local cur prev words cword
    _init_completion &&
    complete -F _pumount pumount



    Some specific questions:



    • Should I be checking that commands such as modinfo actually exist? Which commands don't need checking? (I believe that grep and cut are in "Essential" packages, so can be assumed, but I'm less sure about readlink, for example).

    • Is it guaranteed that /media is the only place to find the mountpoints?

    • How can I make those long lines wrap nicely without becoming even less clear?

    Obviously, any other observations or improvements are invited, too!







    share|improve this question























      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite











      I found a problem with Debian's Bash-completion for pmount and pumount, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.



      I'd like a review of this before sending my new functions with the bug report.



      The original was in /etc/bash_completion.d/pmount, but the modern approach is to have two files in /usr/share/bash-completion/completions/ to support demand-loading of completion functions. We assume that the _init_completion is provided as part of this mechanism, to initialize shell variables cur and prev more usefully than the usual $2 and $3 (e.g. skipping redirection words).



      I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/ to ensure I'm using the device/partition I'm expecting, for example).




      /usr/share/bash-completion/completions/pmount



      _pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
      test "$#devices[@]" -gt 0 &&
      complete -F _pmount pmount



      /usr/share/bash-completion/completions/pumount



      _pumount() 
      # shellcheck disable=SC2034
      local cur prev words cword
      _init_completion &&
      complete -F _pumount pumount



      Some specific questions:



      • Should I be checking that commands such as modinfo actually exist? Which commands don't need checking? (I believe that grep and cut are in "Essential" packages, so can be assumed, but I'm less sure about readlink, for example).

      • Is it guaranteed that /media is the only place to find the mountpoints?

      • How can I make those long lines wrap nicely without becoming even less clear?

      Obviously, any other observations or improvements are invited, too!







      share|improve this question













      I found a problem with Debian's Bash-completion for pmount and pumount, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.



      I'd like a review of this before sending my new functions with the bug report.



      The original was in /etc/bash_completion.d/pmount, but the modern approach is to have two files in /usr/share/bash-completion/completions/ to support demand-loading of completion functions. We assume that the _init_completion is provided as part of this mechanism, to initialize shell variables cur and prev more usefully than the usual $2 and $3 (e.g. skipping redirection words).



      I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/ to ensure I'm using the device/partition I'm expecting, for example).




      /usr/share/bash-completion/completions/pmount



      _pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
      test "$#devices[@]" -gt 0 &&
      complete -F _pmount pmount



      /usr/share/bash-completion/completions/pumount



      _pumount() 
      # shellcheck disable=SC2034
      local cur prev words cword
      _init_completion &&
      complete -F _pumount pumount



      Some specific questions:



      • Should I be checking that commands such as modinfo actually exist? Which commands don't need checking? (I believe that grep and cut are in "Essential" packages, so can be assumed, but I'm less sure about readlink, for example).

      • Is it guaranteed that /media is the only place to find the mountpoints?

      • How can I make those long lines wrap nicely without becoming even less clear?

      Obviously, any other observations or improvements are invited, too!









      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 3 at 10:23
























      asked Apr 3 at 8:58









      Toby Speight

      17.5k13489




      17.5k13489

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          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%2fcodereview.stackexchange.com%2fquestions%2f191141%2fbash-completion-functions-for-pmount-and-pumount%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f191141%2fbash-completion-functions-for-pmount-and-pumount%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?