Skip to content

Commit

Permalink
Add installer
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezcasas committed Apr 22, 2020
1 parent 53b89bc commit 16e5fc6
Show file tree
Hide file tree
Showing 34 changed files with 652 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[scripts/*]
indent_style = space
indent_size = 2

[.zshrc]
indent_style = space
indent_size = 2

[*.md]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2

[karabiner.json]
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shell/zsh/**/**.zwc
shell/zsh/**/**.zwc.old
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[submodule "modules/zimfw"]
path = modules/zimfw
url = [email protected]:zimfw/zimfw.git
[submodule "modules/dotbot"]
path = modules/dotbot
url = [email protected]:anishathalye/dotbot.git
ignore = dirty
[submodule "modules/z"]
path = modules/z
url = [email protected]:rupa/z.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Rafa Gomez [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
</p>

<h1 align="center">
🐢 💨 dotly: Modular and easy to customize dotfiles framework
🐢 💨 dotly: An opinionated Zsh framework focused on dotfiles
</h1>

<p align="center">
<a href="https://github.com/CodelyTV"><img src="https://img.shields.io/badge/CodelyTV-OS-green.svg?style=flat-square" alt="codely.tv"/></a>
<a href="http://pro.codely.tv"><img src="https://img.shields.io/badge/CodelyTV-PRO-black.svg?style=flat-square" alt="CodelyTV Courses"/></a>
</p>

<p align="center">
We've decided to create a framework based on <a href="https://github.com/CodelyTV/dotfiles">our own dotfiles system</a> to let you speed up and improve your setup workflow.
<br />
<br />
<a href="https://github.com/CodelyTV/dotly/stargazers">⭐ Star</a> and <a href="https://github.com/CodelyTV/dotly/watchers">👀 watch</a> to stay tunned 😊</a>
</p>
5 changes: 5 additions & 0 deletions bin/$
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# Useful when you c&p commands from the internet :P

"$@"
45 changes: 45 additions & 0 deletions bin/dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -euo pipefail

source "$DOTLY_PATH/scripts/core/_main.sh"

##? Usage:
##? dot
##? dot <context>
##? dot <context> <cmd> [<args>...]

list_command_paths() {
find "$DOTFILES_PATH/scripts" -maxdepth 2 -perm +111 -type f |
grep -v core |
sort
}

fzf_prompt() {
local paths="$1"

match="$(echo "$paths" |
xargs -I % sh -c 'echo "$(basename $(dirname %)) $(basename %)"' |
fzf --height 100% --preview 'dot $(echo {} | cut -d" " -f 1) $(echo {} | cut -d" " -f 2) -h | bat --style=numbers')"
printf "$match "
read args
if coll::is_empty "$args"; then
dot $match
else
dot $match "$args"
fi
}

if args::has_no_args "$@"; then
fzf_prompt "$(list_command_paths)"
elif args::total_is 1 "$@"; then
fzf_prompt "$(list_command_paths | grep "/$1/")"
else
context="$1"
command="$2"

shift 2
export DOT_TRACE=${TRACE:-false}

"${DOTFILES_PATH}/scripts/${context}/${command}" "$@"
fi
15 changes: 15 additions & 0 deletions bin/git-co
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euo pipefail

source "$DOTFILES_PATH/scripts/core/_main.sh"

##? Checkout alias
#?? 1.0.0
##?
##? Usage:
##? git-co <thing>

docs::eval "$@"

git checkout $thing
17 changes: 17 additions & 0 deletions bin/git-discard
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

source "$DOTFILES_PATH/scripts/core/_main.sh"

##? Reset the status to the last commit
#?? 1.0.0
##?
##? Usage:
##? git-discard

docs::eval "$@"

git add -A
git reset --hard >/dev/null 2>&1
echo 'All changes has been discarded!'
15 changes: 15 additions & 0 deletions bin/git-undo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euo pipefail

source "$DOTFILES_PATH/scripts/core/_main.sh"

##? Delete the last commit, but not the files
#?? 1.0.0
##?
##? Usage:
##? git-undo

docs::eval "$@"

git reset HEAD~1 --mixed
69 changes: 69 additions & 0 deletions installer
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

set -euo pipefail

##? Setups the environment
##?
##? Usage:
##? install

red='\033[0;31m'
green='\033[0;32m'
purple='\033[0;35m'
normal='\033[0m'

_w() {
local -r text="${1:-}"
echo -e "$text"
}
_a() { _w " > $1"; }
_e() { _a "${red}$1${normal}"; }
_s() { _a "${green}$1${normal}"; }
_q() { read -rp "🤔 $1: " "$2"; }

current_timestamp() { date +%s; }

create_dotfiles_dir() {
if [ -d "$1" ]; then
local -r backup_path="$1.$(current_timestamp).back"

_e "The path '$1' already exist"
_s "Creating a backup in '$backup_path'"

mv "$1" "$backup_path"
else
_a "Ok! dotfiles wll be located in: ${purple}$DOTFILES_PATH${normal}"
fi

mkdir -p "$1"
}

_w " ┌────────────────────────────────────┐"
_w "~ │ 🚀 Welcome to the ${green}dotly${normal} installer! │ ~"
_w " └────────────────────────────────────┘"
_w
_q "Where do you want your dotfiles to be located? (default ~/.dotfiles2)" "DOTFILES_PATH"
DOTFILES_PATH="${DOTFILES_PATH:-$HOME/.dotfiles2}"
DOTFILES_PATH="$(eval echo "$DOTFILES_PATH")"

export DOTFILES_PATH="$DOTFILES_PATH"
export DOTLY_PATH="$DOTFILES_PATH/modules/dotly"

create_dotfiles_dir "$DOTFILES_PATH"
cd "$DOTFILES_PATH"

_a "Initializing your dotfiles git repository"
git init >/dev/null

_a "Cloning dotly"
git submodule add "https://github.com/CodelyTV/dotly.git" "$DOTLY_PATH" >/dev/null 2>&1

_a "Installing dotly dependencies"
git submodule update --init --recursive >/dev/null 2>&1

cd "$DOTLY_PATH"

# While debugging
git switch first-version >/dev/null 2>&1

"$PWD/bin/dot" self install
8 changes: 8 additions & 0 deletions scripts/core/_main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

if ! ${DOT_MAIN_SOURCED:-false}; then
source "$DOTLY_PATH/scripts/core/log.sh"
source "$DOTLY_PATH/scripts/core/platform.sh"

readonly DOT_MAIN_SOURCED=true
fi
70 changes: 70 additions & 0 deletions scripts/core/log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

log::ansi() {
local bg=false
case "$@" in
*reset*)
echo "\e[0m"
return 0
;;
*black*) color=30 ;;
*red*) color=31 ;;
*green*) color=32 ;;
*yellow*) color=33 ;;
*blue*) color=34 ;;
*purple*) color=35 ;;
*cyan*) color=36 ;;
*white*) color=37 ;;
esac
case "$@" in
*regular*) mod=0 ;;
*bold*) mod=1 ;;
*underline*) mod=4 ;;
esac
case "$@" in
*background*) bg=true ;;
*bg*) bg=true ;;
esac

if $bg; then
echo "\e[${color}m"
else
echo "\e[${mod:-0};${color}m"
fi
}

if [ -z ${DOT_LOG_FILE+x} ]; then
readonly DOT_LOG_FILE="/tmp/$(basename "$0").log"
fi

_log() {
local template=$1
shift
if ${log_to_file:-false}; then
echoerr -e $(printf "$template" "$@") | tee -a "$DOT_LOG_FILE" >&2
else
echoerr -e $(printf "$template" "$@")
fi
}

_header() {
local TOTAL_CHARS=60
local total=$TOTAL_CHARS-2
local size=${#1}
local left=$((($total - $size) / 2))
local right=$(($total - $size - $left))
printf "%${left}s" '' | tr ' ' =
printf " $1 "
printf "%${right}s" '' | tr ' ' =
}

log::header() { _log "\n$(log::ansi bold)$(log::ansi purple)$(_header "$1")$(log::ansi reset)\n"; }
log::success() { _log "$(log::ansi green)✔ %s$(log::ansi reset)\n" "$@"; }
log::error() { _log "$(log::ansi red)✖ %s$(log::ansi reset)\n" "$@"; }
log::warning() { _log "$(log::ansi yellow)➜ %s$(log::ansi reset)\n" "$@"; }
log::note() { _log "$(log::ansi blue)%s$(log::ansi reset)\n" "$@"; }

die() {
log::error "$@"
exit 42
}
3 changes: 3 additions & 0 deletions scripts/core/platform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
platform::command_exists() {
type "$1" >/dev/null
}
20 changes: 20 additions & 0 deletions scripts/self/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -euo pipefail

source "$DOTLY_PATH/scripts/core/_main.sh"
source "$DOTLY_PATH/scripts/self/utils/install.sh"

##? Install dotly and setup dotfiles
#?? 1.0.0
##?
##? Usage:
##? install

if ! platform::command_exists zsh; then
log::note "Zsh not installed, installing"

"$DOTLY_PATH/bin/dot" package add zsh
else
log::note "Zsh already installed!"
fi
22 changes: 22 additions & 0 deletions scripts/self/utils/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/user/env bash

install_macos_custom() {
# Install brew if not installed
if ! [ -x "$(command -v brew)" ]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

# All apps (This line is 2 times because there are dependencies between brew cask and brew)
brew bundle --file="$DOTLY_PATH/mac/brew/Brewfile" || true
brew bundle --file="$DOTLY_PATH/mac/brew/Brewfile"

# Correct paths (so, we handle all with $PATH)
sudo truncate -s 0 /etc/paths

# Custom macOS "defaults"
sh "$DOTLY_PATH/mac/mac-os.sh"
}

install_linux_custom() {
echo
}
12 changes: 12 additions & 0 deletions shell/_aliases/dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
alias ..="cd .."
alias ...="cd ../.."
alias ll="exa -l"
alias la="exa -la"

# Jumps
alias ~="cd ~"
alias tmp="cd ~/Desktop/tmp"
alias c='cd ~/Code'
alias mines="cd ~/Code/mines"
alias dotfiles="cd ~/.dotfiles"
alias codely="cd ~/Code/codely"
12 changes: 12 additions & 0 deletions shell/_aliases/git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
alias gaa="git add -A"
alias gc="dot git commit"
alias gca="git add --all && git commit --amend --no-edit"
alias gco="git checkout"
alias gd="dot git pretty-diff"
alias gs="git status -sb"
alias gf="git fetch --all -p"
alias gps="git push"
alias gpsf="git push --force"
alias gpl="git pull --rebase --autostash"
alias gb="git branch"
alias gl="dot git pretty-log"
Loading

0 comments on commit 16e5fc6

Please sign in to comment.