#!/usr/bin/env bash usage() { cat 1>&2 <... Upgrade all packages or specified ones dump Dump installed packages to list patch Apply a pre-made patch open Open a dotfile in an editor web Open the repo in the browser EOF } dots-git() { git --git-dir="$HOME/.dotfiles" --work-tree="$HOME" $@; } run-command() { echo "$1"; eval "$1"; } os() { [[ "$(uname -s)" =~ "Darwin" ]] && echo "macOS" [[ "$(uname -r)" =~ "MANJARO" ]] && echo "Manjaro" } err-not-supported() { echo "Operating system not supported for this command" exit 1 } case "$1" in -h | --help | help) usage;; install) case `os` in macOS) run-command 'brew bundle install --global --no-upgrade --no-lock';; Manjaro) run-command 'yay -S --needed - < $HOME/.pkglist.txt';; *) err-not-supported;; esac ;; dump) case `os` in macOS) run-command 'brew bundle dump --global --force';; Manjaro) run-command 'yay -Qqe > $HOME/.pkglist.txt';; *) err-not-supported;; esac ;; upgrade) case `os` in macOS) run-command 'brew upgrade';; Manjaro) run-command 'yay -Syu';; *) err-not-supported;; esac ;; patch) dots-git apply $(dots-git ls-files ${XDG_DATA_HOME:-$HOME/.local/share}/patches | fzf --query "$2" --multi --select-1 --preview="bat --color=always {}");; open) $EDITOR "$HOME/$(git --git-dir="$HOME/.dotfiles" ls-files | fzf --query "$2" --select-1 --preview "bat --color=always $HOME/{}")";; web) gh repo view --web knowler/dotfiles;; issue | pr) gh $@ --repo knowler/dotfiles;; *) dots-git $@;; esac