You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
config/config.sh

122 lines
5.4 KiB

#!/bin/bash
get_var_path() { wslpath "$(cmd.exe /c echo %$1% | tr --delete \\r)"; }
cd "$(dirname "$(readlink --canonicalize "$0")")"
PATH="$PWD/bash/scripts:$PATH"
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-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' \
gcloud- 'Google Cloud SDK' gcloud ' Install' gcloud-config ' Create config symlinks' \
tmux- 'tmux' tmux ' Create config symlinks' \
firefox- 'Firefox' firefox-rebuild-win ' Rebuild configs from templates (Windows)' firefox-link-win ' Create user.js symlinks (Windows)' \
--notags --default-item "$action" 3>&2 2>&1 1>&3-)"
case "$action" in
wsl-scripts)
2path.sh wsl/scripts
;;
wsl-win)
rm --force --recursive ~/win &&
ln --relative --symbolic "$(get_var_path USERPROFILE)" ~/win
;;
wsl-wsltty)
2link.sh "$(get_var_path APPDATA)" wsl/wsltty
;;
bash)
2link.sh ~ bash/config/{.*,*}
;;
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; }
;;
git-delta)
mkdir --parents ~/.bin/delta &&
wget https://github.com"$(curl --silent https://github.com/dandavison/delta/releases | grep --max-count=1 --only-matching '[^\"]*x86_64-unknown-linux-gnu[^\"]*')" --output-document=- | tar --extract --directory ~/.bin/delta --gzip --strip-components=1
;;
git-filter-repo)
[ -d ~/.bin/git-filter-repo ] || { mkdir --parents ~/.bin && git clone https://github.com/newren/git-filter-repo ~/.bin/git-filter-repo; } &&
2path.sh ~/.bin/git-filter-repo/git-filter-repo
;;
git-scripts)
2path.sh git/scripts
;;
vscode-ext)
ext="code --install-extension dbaeumer.vscode-eslint --install-extension eamodio.gitlens --install-extension esbenp.prettier-vscode --install-extension ms-vscode-remote.vscode-remote-extensionpack --install-extension streetsidesoftware.code-spell-checker --install-extension svelte.svelte-vscode" &&
if [ "$root_win" ]; then cmd.exe /c $ext; else $ext; fi
;;
vscode)
2link.sh ~/.config/Code/User vscode/config/* &&
{ [ -z "$root_win" ] || {
2link.sh "$(get_var_path APPDATA)"/Code/User vscode/config/* &&
2link.sh ~/.vscode-server vscode/wsl_server_config/*
}; }
;;
nodejs-npmrc)
2link.sh ~ nodejs/.npmrc
;;
nodejs-config)
2link.sh ~/dev nodejs/config/{.*,*}
;;
nodejs-scripts)
2path.sh nodejs/scripts
;;
gcloud)
[ -d ~/.bin/gcloud ] || { mkdir --parents ~/.bin/gcloud && wget "$(curl --silent https://cloud.google.com/sdk/docs/downloads-versioned-archives | grep --only-matching 'https[^\"]*linux-x86_64.tar.gz')" --output-document=- | tar --extract --directory ~/.bin/gcloud --gzip --strip-components=1; } &&
2path.sh ~/.bin/gcloud/bin/gcloud
;;
gcloud-config)
2link.sh ~/.config gcloud/gcloud
;;
tmux)
2link.sh ~ tmux/.tmux.conf
;;
firefox-rebuild-win)
for dir in firefox/*; do
[ -d "$dir" ] || continue
config="$(basename "$dir")"
echo $'//\n// Generated at '"$(date)"$'\n//' > firefox/"$config"/user.js
IFS='+' read -a pieces <<< "$config"
for piece in "${pieces[@]}"; do
if [ -f firefox/"$piece".js ]; then
echo "// --- $piece.js ---" >> firefox/"$config"/user.js
cat firefox/"$piece".js >> firefox/"$config"/user.js
fi
if [ -f firefox/"$piece".pac ]; then
echo "// --- $piece.pac ---" >> firefox/"$config"/user.js
echo 'user_pref("network.proxy.autoconfig_url", "'file:///"${root_win//\\//}"/firefox/"$piece".pac$'");\nuser_pref("network.proxy.type", 2);' >> firefox/"$config"/user.js
fi
done
done
true
;;
firefox-link-win)
profile_dir="$(get_var_path APPDATA)"/Mozilla/Firefox/Profiles
profiles_args=()
for dir in "$profile_dir"/*; do [ -d "$dir" ] || continue; base="$(basename "$dir")"; profiles_args+=("$base" "$base"); done
configs_args=()
for dir in firefox/*; do [ -d "$dir" ] || continue; base="$(basename "$dir")"; configs_args+=("$base" "$base"); done
while :; do
profile="$(whiptail --title 'Select profile' --menu '' $(tput lines) $(tput cols) $(($(tput lines) - 7)) "${profiles_args[@]}" --notags --default-item "$profile" 3>&2 2>&1 1>&3-)"
[ "$profile" = '' ] && break
config="$(whiptail --title "Link $profile to config" --menu '' $(tput lines) $(tput cols) $(($(tput lines) - 7)) "${configs_args[@]}" --notags --default-item "$config" 3>&2 2>&1 1>&3-)"
[ "$config" = '' ] && break
2link.sh "$profile_dir/$profile" firefox/"$config"/user.js
done
;;
'')
break
;;
*)
false
;;
esac && whiptail --msgbox Done 7 10
done