From 9434b666e5ac37a005a8ae467b448658457dfee8 Mon Sep 17 00:00:00 2001 From: Raine Date: Sat, 14 Oct 2023 22:38:06 +0200 Subject: [PATCH] mod: remodel --- files/%HOME/.config/kanshi/config | 9 +++++ lib/lib.sh | 9 ++++- package.list | 1 - sync.sh | 62 ++++++++++++++++++++++++++----- 4 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 files/%HOME/.config/kanshi/config diff --git a/files/%HOME/.config/kanshi/config b/files/%HOME/.config/kanshi/config new file mode 100644 index 0000000..5a245d2 --- /dev/null +++ b/files/%HOME/.config/kanshi/config @@ -0,0 +1,9 @@ +profile school { + output "Iiyama North America PL2483H 1156290962278" mode 1920x1080 position 0,0 + output eDP-1 mode 1920x1080 position 1920,0 +} + +#profile sharing { +# output HDMI-A-1 mode 1920x1080 position 0,1080 +# output eDP-1 mode 1920x1080 position 0,0 +#} diff --git a/lib/lib.sh b/lib/lib.sh index a7619e1..5ba6f73 100644 --- a/lib/lib.sh +++ b/lib/lib.sh @@ -12,6 +12,11 @@ bool() { } run() { + # Check if command starts with NO_RUN ($*) and remove it + if echo "$*" | grep -q "^NO_RUN"; then + return 0 + fi + if bool "$DRY_RUN"; then echo "DRY: + $*" else @@ -21,7 +26,7 @@ run() { } is_graphical() { - command -v $PREF_TERM && return 0 || return 1 + command -v $PREF_TERM > /dev/null && return 0 || return 1 } -command -v $SYS_SUDO || SYS_SUDO="" \ No newline at end of file +command -v $SYS_SUDO > /dev/null || SYS_SUDO="NO_RUN" diff --git a/package.list b/package.list index 92146dc..bbecb9e 100644 --- a/package.list +++ b/package.list @@ -1,4 +1,3 @@ curl vim zsh - diff --git a/sync.sh b/sync.sh index f6a850e..a753714 100755 --- a/sync.sh +++ b/sync.sh @@ -4,6 +4,9 @@ SYNC_FILES=${SYNC_FILES:-yes} INSTALL_PKGS=${INSTALL_PKGS:-yes} RUN_CMDS=${RUN_CMDS:-yes} PULL_GIT=${PULL_GIT:-yes} +TIME_TRACK=${TIME_TRACK:-no} + +ARGS="$@" . ./lib/lib.sh @@ -11,9 +14,13 @@ set -e # Exit on error _install_pkgs() { run $SYS_SUDO $PM_COMMAND $PM_UPDATE $PM_NOCONFIRM + _APPLICATIONS="" while read -r pkg; do - run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $pkg - done <$1 + [ -z "$pkg" ] && continue + [ "$(echo "$pkg" | cut -c1)" = "#" ] && continue + _APPLICATIONS="$_APPLICATIONS $pkg" + done <"$1" + run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $_APPLICATIONS } _sync_files() { @@ -38,25 +45,60 @@ _run_cmds() { done <./command.list } +ARGS="$@" +_skip_next_arg="n" arg_handler() { - case $1 in - --graphical|-g) - bool "$INSTALL_PKGS" && _install_pkgs ./gpackage.list - ;; - esac + for arg in $ARGS; do + bool $_skip_next_arg && continue + + case $arg in + +files) SYNC_FILES=yes ;; + -files) SYNC_FILES=no ;; + +pkgs) INSTALL_PKGS=yes ;; + -pkgs) INSTALL_PKGS=no ;; + +cmds) RUN_CMDS=yes ;; + -cmds) RUN_CMDS=no ;; + +git) PULL_GIT=yes ;; + -git) PULL_GIT=no ;; + +) SYNC_FILES=yes; INSTALL_PKGS=yes; RUN_CMDS=yes; PULL_GIT=yes ;; + -) SYNC_FILES=no; INSTALL_PKGS=no; RUN_CMDS=no; PULL_GIT=no ;; + +*) + echo "# Unknown argument: $arg" + exit 1 + ;; + -*) + echo "# Unknown argument: $arg" + exit 1 + ;; + esac + done } main() { + arg_handler + + echo "# hook: PULL_GIT" bool "$PULL_GIT" && run git pull + + echo "# hook: SYNC_FILES (/)" bool "$SYNC_FILES" && run cp -a "./files/%HOME/." "$HOME" + + echo "# hook: SYNC_FILES" bool "$SYNC_FILES" && _sync_files + + echo "# hook: INSTALL_PKGS" bool "$INSTALL_PKGS" && _install_pkgs ./package.list - arg_handler "$@" - + echo "# hook: RUN_CMDS" bool "$RUN_CMDS" && _run_cmds + + return 0 } echo "# exec: start." -bool ${TIME_TRACK:-no} && time main "$@" || main "$@" +if bool $TIME_TRACK; then + time main "$@" +else + main "$@" +fi echo "# exec: done."