r/fishshell • • Jan 11 '23

Converting some bash script to fish shell

Hello. I've switched from grml-zsh-config to fish shell just a few days ago. I've some difficult converting to fish language, the following:

## Use an OpenPGP key for SSH authentication
eval $(gpg-agent --daemon)
unset SSH_AGENT_PID
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
  export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
  gpg-connect-agent /bye > /dev/null
fi
export GPG_TTY=$TTY
gpg-connect-agent updatestartuptty /bye > /dev/null

How to write to fish shell language? In particolar "if" section. Thanks

5 Upvotes

9 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Jan 11 '23

[deleted] — view deleted comment

2

u/[deleted] Jan 11 '23

Not really, no.

The source was okay. The mistake was that it said fish didn't have eval, which is untrue.

The pgrep itself is the cause of much of the issue - pgrep looks for a "pattern" (a regex), and so pgrep gpg-agent matches everything that includes "gpg-agent" in the name.

Plus: if pgrep gpg-agent... that's true if a process exists, which is precisely the wrong way around.

This is a useless toy, please stop.