diff options
-rwxr-xr-x | scripts/mkln.sh | 102 | ||||
-rwxr-xr-x | wsl.install | 37 |
2 files changed, 112 insertions, 27 deletions
diff --git a/scripts/mkln.sh b/scripts/mkln.sh new file mode 100755 index 0000000..5220f0f --- /dev/null +++ b/scripts/mkln.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +TEMP=$(getopt -o hvqdf --long help,verbose,quiet,debug,force \ + -n 'javawrap' -- "$@") + +if [ $? != 0 ]; then + echo "Terminating..." >&2 + exit 1 +fi + +eval set -- "$TEMP" + +SCRIPT="$(basename $0)" +VERBOSE=false +QUIET=false +DEBUG=false +FORCE=false + +read -r -d '' USAGE <<-EOF +USAGE: $SCRIPT [OPTIONS] <SOURCE> <TARGET> + +OPTIONS: + -h, --help Show this message + -v, --verbose Show more output + -q, --quiet Suppress all output + -d, --debug NOT IMPLEMENTED + -f, --force Overwrite items + +ARGS: + <SOURCE> <TARGET>... File to link. +EOF + +while true; do + case "$1" in + -h | --help) + echo "$USAGE" + exit 0 + ;; + -v | --verbose) + VERBOSE=true + shift + ;; + -q | --quiet) + QUIET=true + shift + ;; + -d | --debug) + DEBUG=true + shift + ;; + -f | --force) + FORCE=true + shift + ;; + --) + shift + break + ;; + *) + break + ;; + esac +done + +if ! command -v powershell.exe &>/dev/null; then + [ "$QUIET" != true ] && echo "Powershell not found in path." >&2 + exit 1 +fi + +if [ -z "$2" ]; then + 2="$(pwd)" +fi + +[ "$VERBOSE" == true ] && echo "linking $2 -> $1" + +if [ -d "$1" ]; then + [ "$VERBOSE" == true ] && echo "$1 is a directory. Creating junction." + args='/J' +fi + +source=$(wslpath -w $1) +target=$(wslpath -w $(dirname $2))\\$(basename $2) + +if ls -la "$(dirname $2)/" 2>/dev/null | grep -q "$(basename $2)"; then + if [ "$FORCE" == true ]; then + [ "$VERBOSE" == true ] && echo "$(basename $2) exists. Overwriting." + rm -rf "$2" + else + [ "$QUIET" != true ] && echo "$(basename $target) already exists. Use -f to overwrite." >&2 + exit 1 + fi +fi + +mkdir -p "$(dirname $2)" + +cmd="cd ~; cmd /c mklink ${args} ${target} ${source}" + +if [ "$DEBUG" == true ]; then + [ "$QUIET" != true ] && printf '\nCommand: \n%s\n\n' "powershell.exe -c ${cmd} &>/dev/null" +else + powershell.exe -c "${cmd}" &>/dev/null +fi diff --git a/wsl.install b/wsl.install index 6e1b1c3..442021f 100755 --- a/wsl.install +++ b/wsl.install @@ -1,26 +1,7 @@ #!/usr/bin/env bash DOTFILES="${DOTFILES:-${BASEDIR:-${HOME}/dotfiles}}" WINHOME="$(wslpath "$(powershell.exe -NoProfile -c \$HOME)")" -force=1 - -function mkln() { - dir="$(dirname $2)" - file="$(basename $2)" - source=$(wslpath -w $DOTFILES/$1) - target=$(wslpath -w $dir)\\$file - cmd="cd ~; cmd /c mklink $target $source" - - if ls -la $dir/ 2>/dev/null | grep -q $file; then - if [ $force = 1 ]; then - cmd="cd ~; rm $target; cmd /c mklink $target $source" - else - echo "$file already exists. Use -f to overwrite." - return - fi - fi - powershell.exe -c "$cmd" &>/dev/null - echo "linked $2 --> $1" -} +mkln="${DOTFILES}/scripts/mkln.sh -f" function show-warning() { gpgpath=$(wslpath -w "$(command -v gpg.exe)") @@ -41,13 +22,15 @@ ln -sf $WINHOME ~/win ln -sf $WINHOME/Sync ~/win/sync ln -sf $WINHOME/siue ~/win/siue -mkln ssh/win.config ~/win/.ssh/config -mkln gitconfig ~/win/.gitconfig -mkln gnupg/gpg.conf ~/win/AppData/Roaming/gnupg/gpg.conf -mkln gnupg/gpg-agent.conf ~/win/AppData/Roaming/gnupg/gpg-agent.conf -mkln gnupg/scdaemon.conf ~/win/AppData/Roaming/gnupg/scdaemon.conf -mkln wt.json ~/win/AppData/Local/Packages/Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe/LocalState/settings.json -mkln winget.json ~/win/AppData/Local/Packages/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe/LocalState/settings.json +cd $DOTFILES + +$mkln ssh/win.config ~/win/.ssh/config +$mkln gitconfig ~/win/.gitconfig +$mkln gnupg/gpg.conf ~/win/AppData/Roaming/gnupg/gpg.conf +$mkln gnupg/gpg-agent.conf ~/win/AppData/Roaming/gnupg/gpg-agent.conf +$mkln gnupg/scdaemon.conf ~/win/AppData/Roaming/gnupg/scdaemon.conf +$mkln wt.json ~/win/AppData/Local/Packages/Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe/LocalState/settings.json +$mkln winget.json ~/win/AppData/Local/Packages/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe/LocalState/settings.json if gpg.exe --keyserver hkps://keys.openpgp.org --recv-key 0xC8F6E06F5C8E2634 &>/dev/null; then echo "gpg key imported" |