shell/common: refactor; +umask
This commit is contained in:
parent
b9b28c8701
commit
449a98b54e
|
@ -1,11 +1,11 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CACHE_DIR="$DOTFILES/shell/zsh/cache"
|
CACHE_DIR="$DOTFILES/shell/zsh/cache"
|
||||||
|
|
||||||
is-callable() { command -v "$1" >/dev/null; }
|
is-callable() { command -v "$1" >/dev/null; }
|
||||||
is-interactive() { [[ $- == *i* ]]; }
|
is-interactive() { [[ $- == *i* ]]; }
|
||||||
is-root() { [[ "$UID" -eq 0 ]]; }
|
is-root() { [[ "$UID" -eq 0 ]]; }
|
||||||
is-ssh() { [[ "$SSH_CONNECTION" != '' ]]; }
|
is-ssh() { [[ $SSH_CONNECTION ]]; }
|
||||||
|
|
||||||
info() { printf "\r[ \033[00;34m..\033[0m ] $1\n"; }
|
info() { printf "\r[ \033[00;34m..\033[0m ] $1\n"; }
|
||||||
success() { printf "\r\033[2K[ \033[00;32mOK\033[0m ] $1\n"; }
|
success() { printf "\r\033[2K[ \033[00;32mOK\033[0m ] $1\n"; }
|
||||||
|
@ -14,19 +14,18 @@ fail() { printf "\r\033[2K[\033[0;31mFAIL\033[0m] $1\n"; echo; exit; }
|
||||||
load () { source "$DOTFILES/$*"; }
|
load () { source "$DOTFILES/$*"; }
|
||||||
|
|
||||||
loadall () {
|
loadall () {
|
||||||
for file in "$DOTFILES"/$1/*.zsh;
|
for file in "$DOTFILES"/$1/*.zsh; do
|
||||||
do
|
|
||||||
source "$file"
|
source "$file"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
cache() {
|
cache() {
|
||||||
[ -z "$CACHE_DIR" ] && error "Cache not set!"
|
[[ -z "$CACHE_DIR" ]] && error "Cache not set!"
|
||||||
[ ! -d "$CACHE_DIR" ] && mkdir -p "$CACHE_DIR"
|
[[ -d "$CACHE_DIR" ]] || mkdir -p "$CACHE_DIR"
|
||||||
|
|
||||||
is-callable "$1" || return 1
|
is-callable "$1" || return 1
|
||||||
local cache="${CACHE_DIR}/$1-$(basename $SHELL)"
|
local cache="${CACHE_DIR}/$1-$(basename $SHELL)"
|
||||||
if ! [[ -f "$cache" && -s "$cache" ]]; then
|
if [[ ! -f "$cache" && -s "$cache" ]]; then
|
||||||
echo "Caching $1"
|
echo "Caching $1"
|
||||||
$@ > "$cache" 2> /dev/null
|
$@ > "$cache" 2> /dev/null
|
||||||
fi
|
fi
|
||||||
|
@ -34,12 +33,12 @@ cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cache-clear() {
|
cache-clear() {
|
||||||
[ -d "$CACHE_DIR" ] && rm -f "$CACHE_DIR/*"
|
[[ -d $CACHE_DIR ]] && rm -f "$CACHE_DIR/*"
|
||||||
}
|
}
|
||||||
|
|
||||||
repo() {
|
repo() {
|
||||||
if [ ! -d "$2" ];
|
[[ -d $2 ]] || git clone --recursive "https://github.com/$1" "$2"
|
||||||
then
|
|
||||||
git clone "https://github.com/$1" "$2"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
umask 077
|
||||||
|
|
Loading…
Reference in a new issue