2012-03-21 20:05:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
# Add your custom helpers here. Remember, this is just Bash!
|
|
|
|
##############################################################################
|
2013-08-08 03:23:13 +00:00
|
|
|
|
2021-10-26 16:24:06 +00:00
|
|
|
# Init all paths and make sure the directories exist
|
2013-08-08 03:23:13 +00:00
|
|
|
function init_paths_and_vars {
|
|
|
|
# Directory for projects
|
2015-11-03 23:04:57 +00:00
|
|
|
WORKSPACE="$HOME/workspace"
|
2013-08-08 03:23:13 +00:00
|
|
|
# This is in bashrc
|
2015-11-03 23:04:57 +00:00
|
|
|
USER_BIN="$HOME/bin"
|
|
|
|
# Local prefix
|
2016-06-07 00:16:47 +00:00
|
|
|
LOCAL_PREFIX="$HOME/.local"
|
2017-11-14 03:16:25 +00:00
|
|
|
# Local bin
|
|
|
|
LOCAL_BIN="$HOME/.local/bin"
|
2013-08-08 03:23:13 +00:00
|
|
|
# Temp dir for downloads
|
2015-11-03 23:04:57 +00:00
|
|
|
TMP_DIR="$PROJECT_DIR/tmp"
|
2013-08-08 03:23:13 +00:00
|
|
|
# System uname
|
2021-10-26 16:24:06 +00:00
|
|
|
UNAME_STR=$(uname)
|
2015-11-03 23:04:57 +00:00
|
|
|
# XGD_DATA
|
|
|
|
XDG_DATA_HOME="$HOME/.local/share"
|
|
|
|
# XGD_CONFIG
|
|
|
|
XDG_CONFIG_HOME="$HOME/.config"
|
2013-08-08 03:23:13 +00:00
|
|
|
|
|
|
|
# Create workspace dir
|
2021-10-26 16:24:06 +00:00
|
|
|
mkdir -p "$WORKSPACE"
|
|
|
|
mkdir -p "$USER_BIN"
|
|
|
|
mkdir -p "$LOCAL_PREFIX"
|
|
|
|
mkdir -p "$LOCAL_BIN"
|
|
|
|
mkdir -p "$TMP_DIR"
|
|
|
|
mkdir -p "$XDG_DATA_HOME"
|
|
|
|
mkdir -p "$XDG_CONFIG_HOME"
|
2013-08-08 03:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 16:24:06 +00:00
|
|
|
# Create a dotfile and source a synced version
|
2013-08-08 03:23:13 +00:00
|
|
|
function source_dotfile {
|
|
|
|
local RC_PATH=$1
|
2021-10-26 16:24:06 +00:00
|
|
|
local RC_NAME=""
|
|
|
|
RC_NAME=$(basename "$1")
|
2013-08-08 03:23:13 +00:00
|
|
|
local SOURCE_CMD="source"
|
|
|
|
|
|
|
|
# If a source command was passed in, we can use that
|
|
|
|
[ "$2" != "" ] && SOURCE_CMD=$2
|
|
|
|
|
|
|
|
# Check if .bash* file exists
|
|
|
|
if [[ ! ( -f "$HOME/.$RC_NAME" ) ]]; then
|
|
|
|
# Create a blank one
|
|
|
|
touch "$HOME/.$RC_NAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
try_link "$RC_PATH" "$HOME/.${RC_NAME}_sync"
|
|
|
|
|
|
|
|
add_line "#import $RC_NAME from synced" "$HOME/.$RC_NAME"
|
|
|
|
add_line "$SOURCE_CMD ~/.${RC_NAME}_sync" "$HOME/.$RC_NAME"
|
|
|
|
}
|
2021-10-26 16:24:06 +00:00
|
|
|
|
|
|
|
# Check if a recipe is installed, if not install it and mark it installed
|
|
|
|
function install() {
|
|
|
|
if ! is_installed "$1" ; then
|
|
|
|
recipe "$1"
|
|
|
|
set_installed "$1"
|
|
|
|
fi
|
|
|
|
}
|