From 409c98a5bf9e533fc476554cd0df18b6c565d97c Mon Sep 17 00:00:00 2001 From: Alan Faubert Date: Sun, 6 Feb 2022 10:35:57 -0500 Subject: [PATCH] bash: add wsl/*.bashrc --- bash/README.md | 4 ++++ bash/wsl/load_ssh_key.bashrc | 8 ++++++++ bash/wsl/no_privileged_ports.bashrc | 1 + bash/wsl/start_cron_service.bashrc | 1 + config.sh | 5 ++++- 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 bash/wsl/load_ssh_key.bashrc create mode 100644 bash/wsl/no_privileged_ports.bashrc create mode 100644 bash/wsl/start_cron_service.bashrc diff --git a/bash/README.md b/bash/README.md index 24c46e7..d9e1e9e 100644 --- a/bash/README.md +++ b/bash/README.md @@ -12,6 +12,10 @@ If you create additional `~/.bashrc.d/*` or `~/.profile.d/*` files, they will al - [`2path.sh`](scripts/2path.sh) - create symlinks to files or directories from `~/.local/bin`, giving unique names to directories - [`syncfiles.sh`](scripts/syncfiles.sh) - given paths to two or more files, prompt to copy the newest one over each of the ones it differs from +## Optional WSL scripts + +- [`wsl/*.bashrc`](wsl) - scripts to be symlinked to from `~/.bashrc.d/*` for optional WSL-specific enhancements + ## Adding color to root user shells Add this to `/etc/bash.bashrc` diff --git a/bash/wsl/load_ssh_key.bashrc b/bash/wsl/load_ssh_key.bashrc new file mode 100644 index 0000000..3f95751 --- /dev/null +++ b/bash/wsl/load_ssh_key.bashrc @@ -0,0 +1,8 @@ +ssh-add -l > /dev/null 2> /dev/null +if [ $? = 1 ]; then + read -N 1 -p "Load SSH key from Windows clipboard now? [y/n] " -r r + echo + if [ "$r" = y ]; then + powershell.exe -noprofile -command get-clipboard | tr --delete \\r | ssh-add - + fi +fi diff --git a/bash/wsl/no_privileged_ports.bashrc b/bash/wsl/no_privileged_ports.bashrc new file mode 100644 index 0000000..958f18d --- /dev/null +++ b/bash/wsl/no_privileged_ports.bashrc @@ -0,0 +1 @@ +[ "$(sysctl --values net.ipv4.ip_unprivileged_port_start)" = 0 ] || wsl.exe --distribution $WSL_DISTRO_NAME --user $(id --name --user 0) -- sysctl net.ipv4.ip_unprivileged_port_start=0 > /dev/null diff --git a/bash/wsl/start_cron_service.bashrc b/bash/wsl/start_cron_service.bashrc new file mode 100644 index 0000000..a95dec2 --- /dev/null +++ b/bash/wsl/start_cron_service.bashrc @@ -0,0 +1 @@ +service cron status > /dev/null || wsl.exe --distribution $WSL_DISTRO_NAME --user $(id --name --user 0) service cron start diff --git a/config.sh b/config.sh index d158230..452a11d 100755 --- a/config.sh +++ b/config.sh @@ -6,7 +6,7 @@ root_win="$([[ "$(uname --kernel-release)" =~ [Mm]icrosoft ]] && wslpath -w .)" while :; do action="$(whiptail --menu '' $(tput lines) $(tput cols) $(($(tput lines) - 7)) \ wsl- 'WSL' wsl-scripts ' Set up WSL helper scripts' wsl-win ' Create ~/win symlink to %USERPROFILE%' wsl-wsltty ' Create WSLtty config symlinks (Windows)' \ - bash- 'Bash' bash ' Create ~/* symlinks to config' bash-scripts ' Set up util scripts' \ + bash- 'Bash' bash ' Create ~/* symlinks to config' bash-scripts ' Set up util scripts' bash-wsl-bashrc ' Create WSL-specific ~/.bashrc.d/ symlinks' \ git- 'Git' git ' Create config symlinks (Linux+Windows)' git-delta ' Install Delta' git-filter-repo ' Install git-filter-repo' git-scripts ' Set up various scripts' \ vscode- 'VS Code' vscode-ext ' Install extensions (Linux/Windows)' vscode ' Create config symlinks (Linux+Windows)' \ nodejs- 'Node.js' nodejs-npmrc ' Create ~/.npmrc symlink' nodejs-config ' Create ~/dev/* symlinks to config' nodejs-scripts ' Set up various scripts' \ @@ -31,6 +31,9 @@ while :; do bash-scripts) 2path.sh bash/scripts ;; + bash-wsl-bashrc) + 2link.sh ~/.bashrc.d bash/wsl/*.bashrc + ;; git) 2link.sh ~ git/.gitconfig && { [ -z "$root_win" ] || 2link.sh "$(get_var_path USERPROFILE)" git/.gitconfig; }