mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 11:47:43 +02:00
bat-modules: Add working but work-in-progress code
This commit is contained in:
parent
9a92579100
commit
7fa1faf7bf
3
build.sh
3
build.sh
@ -275,9 +275,10 @@ pp_consolidate__do() {
|
|||||||
|
|
||||||
# Inlines constants:
|
# Inlines constants:
|
||||||
# EXECUTABLE_BAT
|
# EXECUTABLE_BAT
|
||||||
|
# EXECUTABLE_GIT
|
||||||
# PROGRAM_*
|
# PROGRAM_*
|
||||||
pp_inline_constants() {
|
pp_inline_constants() {
|
||||||
local constants=("EXECUTABLE_BAT" "PROGRAM")
|
local constants=("EXECUTABLE_BAT" "EXECUTABLE_GIT" "PROGRAM")
|
||||||
|
|
||||||
# Determine the PROGRAM_ constants.
|
# Determine the PROGRAM_ constants.
|
||||||
local nf_constants="$( ( set -o posix ; set) | grep '^PROGRAM_' | cut -d'=' -f1)"
|
local nf_constants="$( ( set -o posix ; set) | grep '^PROGRAM_' | cut -d'=' -f1)"
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
EXECUTABLE_BAT="bat"
|
EXECUTABLE_BAT="bat"
|
||||||
|
EXECUTABLE_GIT="git"
|
||||||
PROGRAM="$(basename "$0" .sh)"
|
PROGRAM="$(basename "$0" .sh)"
|
||||||
PROGRAM_HOMEPAGE="https://github.com/eth-p/bat-extras"
|
PROGRAM_HOMEPAGE="https://github.com/eth-p/bat-extras"
|
||||||
PROGRAM_COPYRIGHT="Copyright (C) 2019-2020 eth-p | MIT License"
|
PROGRAM_COPYRIGHT="Copyright (C) 2019-2020 eth-p | MIT License"
|
||||||
|
@ -22,7 +22,10 @@ hook_version
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
COMMON_URL_GITHUB="https://github.com/%s.git"
|
COMMON_URL_GITHUB="https://github.com/%s.git"
|
||||||
COMMON_URL_GITLAB="https://gitlab.com/%s.git"
|
COMMON_URL_GITLAB="https://gitlab.com/%s.git"
|
||||||
MODULES_FILE="$(bat --config-dir)/modules.txt"
|
CONFIG_DIR="$(bat --config-dir)"
|
||||||
|
SYNTAX_DIR="${CONFIG_DIR}/syntaxes"
|
||||||
|
THEME_DIR="${CONFIG_DIR}/themes"
|
||||||
|
MODULES_FILE="${CONFIG_DIR}/modules.txt"
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Options:
|
# Options:
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@ -52,6 +55,8 @@ done
|
|||||||
|
|
||||||
# Ensures that the modules file at $MODULES_FILE exists.
|
# Ensures that the modules file at $MODULES_FILE exists.
|
||||||
# If it doesn't, this will print a friendly warning and exit with exit code 1.
|
# If it doesn't, this will print a friendly warning and exit with exit code 1.
|
||||||
|
#
|
||||||
|
# This will also make sure the syntaxes and themes directories exist.
|
||||||
ensure_setup() {
|
ensure_setup() {
|
||||||
if ! [[ -f "$MODULES_FILE" ]]; then
|
if ! [[ -f "$MODULES_FILE" ]]; then
|
||||||
printc "%{YELLOW}The bat-modules modules file wasn't found.%{CLEAR}\n"
|
printc "%{YELLOW}The bat-modules modules file wasn't found.%{CLEAR}\n"
|
||||||
@ -59,6 +64,9 @@ ensure_setup() {
|
|||||||
printc "%{YELLOW}read the documentation at %{CLEAR}%s%{YELLOW} for more info.%{CLEAR}\n" "${PROGRAM_HOMEPAGE}"
|
printc "%{YELLOW}read the documentation at %{CLEAR}%s%{YELLOW} for more info.%{CLEAR}\n" "${PROGRAM_HOMEPAGE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
mkdir -p "${SYNTAX_DIR}" &>/dev/null || true
|
||||||
|
mkdir -p "${THEME_DIR}" &>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Prints an error message that parsing
|
# Prints an error message that parsing
|
||||||
@ -183,13 +191,50 @@ action:clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
action:update() {
|
action:update() {
|
||||||
|
CHANGES=false
|
||||||
|
|
||||||
dsl_on_command_commit() {
|
dsl_on_command_commit() {
|
||||||
echo "$BM_SOURCE"
|
case "$BM_TYPE" in
|
||||||
|
syntax) cd "$SYNTAX_DIR" ;;
|
||||||
|
theme) cd "$THEME_DIR" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
local hash
|
||||||
|
local name="$(parse_source_name "$BM_SOURCE")"
|
||||||
|
printc "%{BLUE}----- %s: %s -----%{CLEAR}\n" "$BM_TYPE" "$name"
|
||||||
|
|
||||||
|
# If it isn't cloned, clone it.
|
||||||
|
if ! [[ -d "$name" ]]; then
|
||||||
|
printc "%{YELLOW}Cloning...%{CLEAR}\n"
|
||||||
|
"$EXECUTABLE_GIT" clone "$BM_SOURCE" "$name"
|
||||||
|
CHANGES=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If it is cloned, fetch/checkout.
|
||||||
|
printc "%{YELLOW}Updating...%{CLEAR}\n"
|
||||||
|
cd "$name"
|
||||||
|
hash="$("$EXECUTABLE_GIT" rev-parse HEAD)"
|
||||||
|
"$EXECUTABLE_GIT" fetch origin --quiet
|
||||||
|
"$EXECUTABLE_GIT" checkout "$BM_OPT_CHECKOUT" --quiet
|
||||||
|
hash_new="$("$EXECUTABLE_GIT" rev-parse HEAD)"
|
||||||
|
|
||||||
|
if [[ "$hash" != "$hash_new" ]]; then
|
||||||
|
printc "%{YELLOW}Updated to %s.%{CLEAR}\n" "$hash_new"
|
||||||
|
CHANGES=true
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse the DSL.
|
# Parse the DSL.
|
||||||
ensure_setup
|
ensure_setup
|
||||||
dsl_parse_file "$MODULES_FILE"
|
dsl_parse_file "$MODULES_FILE"
|
||||||
|
|
||||||
|
# If there are changes, update.
|
||||||
|
printc "%{BLUE}----- bat-modules -----%{CLEAR}\n" "$BM_TYPE" "$name"
|
||||||
|
printc "%{YELLOW}Done.%{CLEAR}\n"
|
||||||
|
if "$CHANGES"; then
|
||||||
|
printc "%{YELLOW}Rebuilding cache...%{CLEAR}\n"
|
||||||
|
"$EXECUTABLE_BAT" cache --build
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user