Uploaded image for project: 'Funtoo Linux'
  1. Funtoo Linux
  2. FL-2006

Keychain --eval code for Fish is missing semicolons

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Fish 2.1.1

      Description

      The code keychain --eval emits for fish looks like

      set -e SSH_AUTH_SOCK; and set -x -U SSH_AUTH_SOCK /tmp/ssh-7BecKqFiVNce/agent.2580
      set -e SSH_AGENT_PID; and set -x -U SSH_AGENT_PID 2767
      
      set -e GPG_AGENT_INFO; and set -x -U GPG_AGENT_INFO /tmp/gpg-23iZ8D/S.gpg-agent:2768:1
      

      If you try to eval this, Fish doesn't interpret the newline as a new command, and jams set -e SSH_AGENT onto the end of SSH_AUTH_SOCK, and so on. A simple workaround: swap out newlines for semicolons in your .config/fish/config.fish:

      # Load SSH Keys
      if status --is-interactive
        eval (keychain --eval --quiet -Q id_rsa | tr \n \;)
      end
      

        Attachments

          Activity

          Hide
          drobbins Daniel Robbins added a comment -

          Try running keychain without --eval, then:

          drobbins@dualhead ~/keychain.new> . ~/.keychain/dualhead-fish

          This will source the file with the proper syntax. Does this work? If so, I'd call this a documentation bug. Need to add info on alternate shells to the wiki and other docs.

          Show
          drobbins Daniel Robbins added a comment - Try running keychain without --eval, then: drobbins@dualhead ~/keychain.new> . ~/.keychain/dualhead-fish This will source the file with the proper syntax. Does this work? If so, I'd call this a documentation bug. Need to add info on alternate shells to the wiki and other docs.
          Hide
          eridius Kevin Ballard added a comment - - edited

          Fish's eval command interprets newlines just fine. The problem is the given code uses command substitution. Fish's command substitution splits on newlines by default, producing an array. And when arrays are used as parameters, they're passed as multiple arguments. So each line is a separate argument to eval, and eval handles that by joining all arguments with a single space.

          The simplest way to handle this is to pipe to source instead of using eval:

          if status --is-interactive
            keychain --eval --quiet -Q id_rsa | source
          end
          

          Alternatively if you wish to still use eval (which really is just a wrapper around piping to source, although it does some job control manipulation that isn't relevant here) you would use

          if status --is-interactive
            set -l IFS # this temporarily clears IFS, which disables the newline-splitting
            eval (keychain --eval --quiet -Q id_rsa)
          end
          
          Show
          eridius Kevin Ballard added a comment - - edited Fish's eval command interprets newlines just fine. The problem is the given code uses command substitution. Fish's command substitution splits on newlines by default, producing an array. And when arrays are used as parameters, they're passed as multiple arguments. So each line is a separate argument to eval , and eval handles that by joining all arguments with a single space. The simplest way to handle this is to pipe to source instead of using eval : if status --is-interactive keychain --eval --quiet -Q id_rsa | source end Alternatively if you wish to still use eval (which really is just a wrapper around piping to source , although it does some job control manipulation that isn't relevant here) you would use if status --is-interactive set -l IFS # this temporarily clears IFS, which disables the newline-splitting eval (keychain --eval --quiet -Q id_rsa) end
          Hide
          drobbins Daniel Robbins added a comment -

          Updated wiki docs and git repo man page with this information. Thanks!

          Show
          drobbins Daniel Robbins added a comment - Updated wiki docs and git repo man page with this information. Thanks!

            People

            • Assignee:
              Unassigned
              Reporter:
              aphyr aphyr null
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: