From a76bf33bfd467d68b46794b374ef32603b3fd76b Mon Sep 17 00:00:00 2001 From: numToStr Date: Wed, 14 Jul 2021 20:08:33 +0530 Subject: [PATCH 1/4] bin: added dotfiles cli --- bin/.local/bin/dotfiles | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 bin/.local/bin/dotfiles diff --git a/bin/.local/bin/dotfiles b/bin/.local/bin/dotfiles new file mode 100755 index 00000000..4a33c9b6 --- /dev/null +++ b/bin/.local/bin/dotfiles @@ -0,0 +1,56 @@ +#!/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() { + case $1 in + -v|--version) + version + shift # past argument + ;; + -h|--help) + help + shift # past argument + ;; + setup) + echo "~>> [[ DOTFILES ]] <<~" + echo + ;; + install) + echo "~>> [[ Installing ]] <<~" + echo + ;; + update) + echo "~>> [[ Updating ]] <<~" + echo + ;; + purge) + echo "~>> [[ Purging ]] <<~" + echo + ;; + esac +} + +main "$@" From d1bf289f812e18c2abbd16e2bcbb91acbcc708ad Mon Sep 17 00:00:00 2001 From: numToStr Date: Wed, 14 Jul 2021 20:22:41 +0530 Subject: [PATCH 2/4] scripts: install them via stow --- Makefile | 16 +++++++++------- scripts/{ => .dotscripts}/install | 4 ++-- scripts/{ => .dotscripts}/post_setup | 0 scripts/{ => .dotscripts}/purge | 4 ++-- scripts/{ => .dotscripts}/setup | 0 scripts/{ => .dotscripts}/update | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) rename scripts/{ => .dotscripts}/install (89%) rename scripts/{ => .dotscripts}/post_setup (100%) rename scripts/{ => .dotscripts}/purge (87%) rename scripts/{ => .dotscripts}/setup (100%) rename scripts/{ => .dotscripts}/update (84%) diff --git a/Makefile b/Makefile index c65d89f2..dbe9e2d1 100644 --- a/Makefile +++ b/Makefile @@ -2,25 +2,27 @@ .DEFAULT_GOAL = setup +SCRIPT_PATH = ./scripts/.dotscripts + setup: @echo "~>> [[ DOTFILES ]] <<~" @echo "" - @bash -c ./scripts/setup - @bash -c ./scripts/install - @bash -c ./scripts/post_setup + @bash -c $(SCRIPT_PATH)/setup + @bash -c $(SCRIPT_PATH)/install + @bash -c $(SCRIPT_PATH)/post_setup install: @echo "~>> [[ Installing ]] <<~" @echo "" - @bash -c ./scripts/install + @bash -c $(SCRIPT_PATH)/install update: @echo "~>> [[ Updating ]] <<~" @echo "" - @bash -c ./scripts/update - @bash -c ./scripts/install + @bash -c $(SCRIPT_PATH)/update + @bash -c $(SCRIPT_PATH)/install purge: @echo "~>> [[ Purging ]] <<~" @echo "" - @bash -c ./scripts/purge + @bash -c $(SCRIPT_PATH)/purge diff --git a/scripts/install b/scripts/.dotscripts/install similarity index 89% rename from scripts/install rename to scripts/.dotscripts/install index acae1836..ef697c2a 100755 --- a/scripts/install +++ b/scripts/.dotscripts/install @@ -2,9 +2,9 @@ set -e -# Moving one directory upwards to the root of the dotfiles +# Moving two directory upwards to the root of the dotfiles # from the scripts/ directory where this script -cd "$(dirname "$0")/.." +cd "$(dirname "$0")/../.." export DOTFILES=$(pwd -P) TARGET=$HOME diff --git a/scripts/post_setup b/scripts/.dotscripts/post_setup similarity index 100% rename from scripts/post_setup rename to scripts/.dotscripts/post_setup diff --git a/scripts/purge b/scripts/.dotscripts/purge similarity index 87% rename from scripts/purge rename to scripts/.dotscripts/purge index f25299f7..a1009053 100755 --- a/scripts/purge +++ b/scripts/.dotscripts/purge @@ -2,9 +2,9 @@ set -e -# Moving one directory upwards to the root of the dotfiles +# Moving two directory upwards to the root of the dotfiles # from the scripts/ directory where this script -cd "$(dirname "$0")/.." +cd "$(dirname "$0")/../.." export DOTFILES=$(pwd -P) TARGET=$HOME diff --git a/scripts/setup b/scripts/.dotscripts/setup similarity index 100% rename from scripts/setup rename to scripts/.dotscripts/setup diff --git a/scripts/update b/scripts/.dotscripts/update similarity index 84% rename from scripts/update rename to scripts/.dotscripts/update index 5aff52c6..0fb91aa5 100755 --- a/scripts/update +++ b/scripts/.dotscripts/update @@ -2,9 +2,9 @@ set -e -# Moving one directory upwards to the root of the dotfiles +# Moving two directory upwards to the root of the dotfiles # from the scripts/ directory where this script -cd "$(dirname "$0")/.." +cd "$(dirname "$0")/../.." REPO="https://github.com/numToStr/dotfiles.git" From 3a5cc2577301a90525e1a10ca7bd03d16e926567 Mon Sep 17 00:00:00 2001 From: numToStr Date: Wed, 14 Jul 2021 20:45:35 +0530 Subject: [PATCH 3/4] scripts: allow scripts/ to installed via stow --- scripts/.dotscripts/install | 5 ----- scripts/.dotscripts/purge | 4 ---- 2 files changed, 9 deletions(-) diff --git a/scripts/.dotscripts/install b/scripts/.dotscripts/install index ef697c2a..b25ba89f 100755 --- a/scripts/.dotscripts/install +++ b/scripts/.dotscripts/install @@ -13,11 +13,6 @@ TARGET=$HOME 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 a1009053..4f7a7bdd 100755 --- a/scripts/.dotscripts/purge +++ b/scripts/.dotscripts/purge @@ -13,10 +13,6 @@ TARGET=$HOME DOTFILES_DIRS=$(ls -d $DOTFILES/*/ | awk -F "/" '{ print $(NF-1) }') for F in $DOTFILES_DIRS ; do - if [[ $F = "bin" ]] || [[ $F = "scripts" ]]; then - continue; - fi - echo "~ Purging :: $F" # Remove previous links From a18a6b60d440b32765b16bfd00ca9e8627184ba9 Mon Sep 17 00:00:00 2001 From: numToStr Date: Wed, 14 Jul 2021 21:15:27 +0530 Subject: [PATCH 4/4] wip --- Makefile | 3 +++ bin/.local/bin/dotfiles | 2 ++ scripts/.dotscripts/install | 14 ++++++++++---- scripts/.dotscripts/purge | 14 ++++++++++---- scripts/.dotscripts/update | 12 +++++++++--- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index dbe9e2d1..84eae3b8 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ .DEFAULT_GOAL = setup SCRIPT_PATH = ./scripts/.dotscripts +MAKE_DOTFILES = 1 + +export MAKE_DOTFILES setup: @echo "~>> [[ DOTFILES ]] <<~" diff --git a/bin/.local/bin/dotfiles b/bin/.local/bin/dotfiles index 4a33c9b6..edcdb4cf 100755 --- a/bin/.local/bin/dotfiles +++ b/bin/.local/bin/dotfiles @@ -25,6 +25,7 @@ help() { } main() { + DOTFILES_CLI="1" case $1 in -v|--version) version @@ -40,6 +41,7 @@ main() { ;; install) echo "~>> [[ Installing ]] <<~" + source $HOME/.dotscripts/install echo ;; update) diff --git a/scripts/.dotscripts/install b/scripts/.dotscripts/install index b25ba89f..b7facd46 100755 --- a/scripts/.dotscripts/install +++ b/scripts/.dotscripts/install @@ -2,11 +2,17 @@ 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` diff --git a/scripts/.dotscripts/purge b/scripts/.dotscripts/purge index 4f7a7bdd..589188db 100755 --- a/scripts/.dotscripts/purge +++ b/scripts/.dotscripts/purge @@ -2,11 +2,17 @@ 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` 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"