#!/bin/sh # This shell script conforms to POSIX. # An interrupt (typically ^C) has the effect of aborting the current command trap 'e_error "Abort the command that is in progress"; exit 1' INT trap 'e_error "Some error has occurred"; exit 1' ERR set -e set -u # Pilot of dotfiles # It shows the use of dotfiles and describe what is inside # regardless of execution or non-execution # http://patorjk.com/software/taag/#p=display&h=1&f=Slant&t=dotfiles # cat <<-'EOT' __ __ ____ _ __ ____/ /____ / /_ / __/(_)/ /___ _____ / __ // __ \ / __// /_ / // // _ \ / ___/ / /_/ // /_/ // /_ / __// // // __/(__ ) \__,_/ \____/ \__//_/ /_//_/ \___//____/ *** WHAT'S INSIDE? *** 1. Download https://github.com/djmonta/dotfiles.git 2. Symlinking dot files to your home directory 3. Execute all sh files within 'etc/init/` (optional) See the README for documentation. https://github.com/djmonta/dotfiles Copyright (c) 2015 "Sachiko Miyamoto" aka @djmonta Licensed under the MIT license. EOT # Insert newline e_newline() { printf "\n"; } # Normal style of writing e_header() { printf "\n\033[1m%s\033[0m\n" "$*"; } # Success e_success() { printf " \033[1;32m✔\033[0m %s\n" "$*"; } # Failure e_error() { printf " \033[1;31m✖\033[0m %s\n" "$*" 1>&2; } # Result e_arrow() { printf " \033[1;34m➜\033[0m %s\n" "$*"; } # Check if exists #is_exist() { which "$1" >/dev/null 2>&1; return $?; } is_exist() { [ -x "$(which "$1")" ]; } # Set dotfiles environment valuable DOTFILES=$HOME/dotfiles; export DOTFILES installing_dotfiles() { # If $DOTFILES already exists, removing the directory if [ -d $DOTFILES ]; then e_header "$DOTFILES: already exists, removing..." rm -rf "$DOTFILES" #mv -f $DOTFILES ${DOTFILES}.old fi # 1. Download the repository # ==> downloading # Priority: git > curl > wget e_header 'Downloading dotfiles...' if is_exist 'git'; then # --recursive equals to ... # git submodule init # git submodule update git clone --recursive https://github.com/djmonta/dotfiles.git "$DOTFILES" else local zip_url='https://github.com/djmonta/dotfiles/archive/master.zip' # Ensure the workplace mkdir -p /tmp/$$ && cd /tmp/$$ if is_exist 'curl'; then curl -L -o dotfiles.zip "$zip_url" elif is_exist 'wget'; then wget -O dotfiles.zip "$zip_url" else e_error 'not found downloader' return 1 fi # Expand the zip to dotfiles directory # and move to $DOTFILES unzip dotfiles.zip mv dotfiles-master "$DOTFILES" fi && e_success 'done' # 2. Deploy dotfiles to your home directory # ==> deploying cd "$DOTFILES" e_header 'Deploying dotfiles...' if make deploy; then e_success 'done' fi # 3. Execute all sh files within etc/init/ # ==> initializing if [ "${1:-}" = 'init' ]; then e_header 'Initializing...' # make_init if make init; then e_success 'done' fi fi e_newline #if [ -p /dev/stdout ]; then # Restart shell if specified "bash -c $(curl -L {URL})" # not restart: # curl -L {URL} | bash e_arrow 'Restarting your shell...' exec "${SHELL:-/bin/zsh}" #else # e_arrow 'Restart your shell, manually' #fi } # Main # # Check if run from a command line # python-like "if __name__ == '__main__':" # # A SAFETY system # Note: This script is designed to be run from a command line shell. if [ "$0" = "${BASH_SOURCE:-}" ]; then e_error 'WARNING!!' e_error 'You should NOT run directly from the command line' e_error 'For more info, see https://github.com/djmonta/dotfiles' e_newline # Push off the safety catch if [ "${1:-}" != 'directly' ]; then exit 1 fi fi installing_dotfiles "$@" e_success 'All done'