summaryrefslogtreecommitdiffstatshomepage
path: root/zsh/wsl.zsh
blob: b742150c1c6087f97c3e8e4a606cb8b14f0ff7f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
path=( $path $HOME/.local/bin $HOME/.dotnet/tools )
hash -d w=/mnt/c/Users/$USER

alias cb=clip.exe
alias wsl=wsl.exe
alias ykman="/mnt/c/Program\ Files/Yubico/YubiKey\ Manager/ykman.exe"

function wt() { powershell.exe -NoProfile -c "wt $@" }

function winget() {
  cmd="winget.exe $1"
  shift # past cmd

  while [[ $# -gt 0 ]]
  do
    key="$1"
    case $key in
        -*) # key value pair
        cmd+=" $key '$2'"
        shift # past argument
        shift # past value
        ;;
        *)    # positional argument
        cmd+=" '$1'" # add it to the list
        shift # past argument
        ;;
    esac
  done
  
  powershell.exe -NoProfile -c "$cmd"
}

function r-copy() {
  if ((REGION_ACTIVE)) then
    zle copy-region-as-kill
    (( ${+aliases[cb]} )) && printf "$CUTBUFFER" | cb
  else
    zle kill-whole-line
  fi
}

function r-cut() {
  if ((REGION_ACTIVE)) then
    zle kill-region
  else
    zle kill-whole-line
  fi
  (( ${+aliases[cb]} )) && printf "$CUTBUFFER" | cb
}

# https://github.com/benpye/wsl-ssh-pageant
# https://github.com/drduh/YubiKey-Guide#remote-host-configuration
# https://dev.to/dzerycz/series/11353
# SSH Socket
# Removing Linux SSH socket and replacing it by link to wsl2-ssh-pageant socket
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0 ]; then
    rm -f $SSH_AUTH_SOCK
    (setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$ZSH_BASE/ssh/wsl2-ssh-pageant.exe" &>/dev/null &)
fi
# GPG Socket
# Removing Linux GPG Agent socket and replacing it by link to wsl2-ssh-pageant GPG socket
export GPG_AGENT_SOCK=$HOME/.gnupg/S.gpg-agent
ss -a | grep -q $GPG_AGENT_SOCK
if [ $? -ne 0 ]; then
    rm -rf $GPG_AGENT_SOCK
    (setsid nohup socat UNIX-LISTEN:$GPG_AGENT_SOCK,fork EXEC:"$ZSH_BASE/ssh/wsl2-ssh-pageant.exe --gpg S.gpg-agent" &>/dev/null &)
fi

alias gpgrst=gpg-reset
# Reload
function gpg-reset() {
  gpg-connect-agent.exe KILLAGENT /bye &>/dev/null
  [ -e $GPG_AGENT_SOCK ] && rm $GPG_AGENT_SOCK
  [ -e $SSH_AUTH_SOCK ] && rm $SSH_AUTH_SOCK
  pkill -f 'socat.*wsl2-ssh-pageant.exe'
  gpg-connect-agent.exe /bye &>/dev/null
  (setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$ZSH_BASE/ssh/wsl2-ssh-pageant.exe" &>/dev/null &)
  (setsid nohup socat UNIX-LISTEN:$GPG_AGENT_SOCK,fork EXEC:"$ZSH_BASE/ssh/wsl2-ssh-pageant.exe --gpg S.gpg-agent" &>/dev/null &)
}