diff --git a/bin/.local/bin/dotfiles b/bin/.local/bin/dotfiles new file mode 100755 index 00000000..edcdb4cf --- /dev/null +++ b/bin/.local/bin/dotfiles @@ -0,0 +1,58 @@ +#!/bin/zsh + +version() { + echo ".dotfiles - $(git rev-parse --short HEAD)" +} + +help() { + version + echo "The things that you can't live without" + echo + echo "USAGE: + dotfiles [FLAGS] + " + echo "FLAGS: + -v, --version Prints version + -h, --help Prints help information + " + echo "COMMAND: + setup Set up the dotfiles on a new machine + install Reinstall the dotfiles + update Fetch latest commits and updates dotfiles + purge Removes everything + " + echo "Give a star @ https://github.com/numToStr/dotfiles" +} + +main() { + DOTFILES_CLI="1" + case $1 in + -v|--version) + version + shift # past argument + ;; + -h|--help) + help + shift # past argument + ;; + setup) + echo "~>> [[ DOTFILES ]] <<~" + echo + ;; + install) + echo "~>> [[ Installing ]] <<~" + source $HOME/.dotscripts/install + echo + ;; + update) + echo "~>> [[ Updating ]] <<~" + echo + ;; + purge) + echo "~>> [[ Purging ]] <<~" + echo + ;; + esac +} + +main "$@" diff --git a/scripts/.dotscripts/install b/scripts/.dotscripts/install index a5e7f783..b7facd46 100755 --- a/scripts/.dotscripts/install +++ b/scripts/.dotscripts/install @@ -2,22 +2,23 @@ set -e -# Moving two directory upwards to the root of the dotfiles -# from the scripts/ directory where this script -cd "$(dirname "$0")/../.." +# If ran through `dotfiles-cli` then `$DOTFILES_CLI` is set +# In that case, hopefully $DOTFILES will be available if `setup` is already performed +# This check prevents $DOTFILES not to be set again which is useful for the cli +if [[ -z $DOTFILES_CLI ]]; then + # Moving two directory upwards to the root of the dotfiles + # from the scripts/ directory where this script + cd "$(dirname "$0")/../.." + + export DOTFILES=$(pwd -P) +fi -export DOTFILES=$(pwd -P) TARGET=$HOME # List of packages that has to installed via `stow` DOTFILES_DIRS=$(ls -d $DOTFILES/*/ | awk -F "/" '{ print $(NF-1) }') for F in $DOTFILES_DIRS ; do - # Don't install scripts/ - # if [[ $F = "scripts" ]]; then - # continue; - # fi - echo "~ Installing :: $F" # Remove previous links diff --git a/scripts/.dotscripts/purge b/scripts/.dotscripts/purge index 2e5b2ab9..589188db 100755 --- a/scripts/.dotscripts/purge +++ b/scripts/.dotscripts/purge @@ -2,21 +2,23 @@ set -e -# Moving two directory upwards to the root of the dotfiles -# from the scripts/ directory where this script -cd "$(dirname "$0")/../.." +# If ran through `dotfiles-cli` then `$DOTFILES_CLI` is set +# In that case, hopefully $DOTFILES will be available if `setup` is already performed +# This check prevents $DOTFILES not to be set again which is useful for the cli +if [[ -z $DOTFILES_CLI ]]; then + # Moving two directory upwards to the root of the dotfiles + # from the scripts/ directory where this script + cd "$(dirname "$0")/../.." + + export DOTFILES=$(pwd -P) +fi -export DOTFILES=$(pwd -P) TARGET=$HOME # List of packages that has to installed via `stow` DOTFILES_DIRS=$(ls -d $DOTFILES/*/ | awk -F "/" '{ print $(NF-1) }') for F in $DOTFILES_DIRS ; do - # if [[ $F = "scripts" ]]; then - # continue; - # fi - echo "~ Purging :: $F" # Remove previous links diff --git a/scripts/.dotscripts/update b/scripts/.dotscripts/update index 0fb91aa5..419410a8 100755 --- a/scripts/.dotscripts/update +++ b/scripts/.dotscripts/update @@ -2,9 +2,15 @@ set -e -# Moving two directory upwards to the root of the dotfiles -# from the scripts/ directory where this script -cd "$(dirname "$0")/../.." +# If ran through `dotfiles-cli` then `$DOTFILES_CLI` is set +if [[ -z $DOTFILES_CLI ]]; then + # Moving two directory upwards to the root of the dotfiles + # from the scripts/ directory where this script + cd "$(dirname "$0")/../.." +else + # Need to cd into `$DOTFILES` so that update channel can be set + cd $DOTFILES +fi REPO="https://github.com/numToStr/dotfiles.git"