Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dotfiles-cli #9

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions bin/.local/bin/dotfiles
Original file line number Diff line number Diff line change
@@ -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] <SUBCOMMAND>
"
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 "$@"
19 changes: 10 additions & 9 deletions scripts/.dotscripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions scripts/.dotscripts/purge
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions scripts/.dotscripts/update
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down