diff options
| -rwxr-xr-x | config/i3/scripts/keyboard_switch | 14 | ||||
| -rwxr-xr-x | config/i3/scripts/pass | 6 | ||||
| -rwxr-xr-x | config/sway/scripts/pass | 6 | ||||
| -rwxr-xr-x | config/waybar/email.sh | 2 | ||||
| -rwxr-xr-x | install | 6 | ||||
| -rwxr-xr-x | local/bin/allsync | 60 | ||||
| -rwxr-xr-x | local/bin/project-test | 30 | ||||
| -rw-r--r-- | utils/ask | 24 | ||||
| -rw-r--r-- | utils/guix | 16 | ||||
| -rw-r--r-- | utils/inst | 53 |
10 files changed, 122 insertions, 95 deletions
diff --git a/config/i3/scripts/keyboard_switch b/config/i3/scripts/keyboard_switch index 7ba27f8..168d577 100755 --- a/config/i3/scripts/keyboard_switch +++ b/config/i3/scripts/keyboard_switch @@ -1,13 +1,13 @@ #!/bin/bash -active=`~/.config/i3/scripts/keyboard_layout` +active=$(~/.config/i3/scripts/keyboard_layout) case "$active" in - us) - setxkbmap cz_qwerty - ;; - cz_qwerty) - setxkbmap us - ;; +us) + setxkbmap cz_qwerty + ;; +cz_qwerty) + setxkbmap us + ;; esac # Send update to i3blocks diff --git a/config/i3/scripts/pass b/config/i3/scripts/pass index aa2ad96..4777c1c 100755 --- a/config/i3/scripts/pass +++ b/config/i3/scripts/pass @@ -1,6 +1,6 @@ #!/bin/sh -find ~/.password-store -type f -printf '%P\n' | \ - sed 's/\.gpg$//' | dmenu -p 'Pass:' | \ +find ~/.password-store -type f -printf '%P\n' | + sed 's/\.gpg$//' | dmenu -p 'Pass:' | while read -r psw; do pass -c "$psw" -done + done diff --git a/config/sway/scripts/pass b/config/sway/scripts/pass index 06383b3..11700e6 100755 --- a/config/sway/scripts/pass +++ b/config/sway/scripts/pass @@ -1,6 +1,6 @@ #!/bin/sh -find ~/.password-store -name .git -prune -o -type f -printf '%P\n' | \ - sed 's/\.gpg$//' | wofi -d -p 'Pass:' | \ +find ~/.password-store -name .git -prune -o -type f -printf '%P\n' | + sed 's/\.gpg$//' | wofi -d -p 'Pass:' | while read -r psw; do pass -c "$psw" -done + done diff --git a/config/waybar/email.sh b/config/waybar/email.sh index 437566f..16b0d9f 100755 --- a/config/waybar/email.sh +++ b/config/waybar/email.sh @@ -10,7 +10,7 @@ fi part=() for mail in email gmail elektroline fel; do counts="$(notmuch count -- "${filter[@]}" and "tag:$mail")" - [ "$counts" = "0" ] || \ + [ "$counts" = "0" ] || part+=("$mail:$counts") done @@ -8,7 +8,9 @@ git submodule update --init --recursive || ( ) # Source inst and diff function +. ./utils/ask . ./utils/inst +. ./utils/guix # Load if we force changes (implies no interaction) [ "$1" = "-f" ] && FORCE=true || FORCE=false @@ -37,9 +39,11 @@ if ask "nix" "Install Nix configuration"; then inst private/config/nix/builders ~/.config/nix/builders fi -if ask "guix" "Install Guix configuration"; then +if hascmd guix && ask "guix" "Install Guix configuration"; then inst guile ~/.guile inst config/guix/channels.scm ~/.config/guix/channels.scm + guix_install \ + guile guile-colorized guile-readline guile-lsp-server fi if ask "cliutils" "Install configurations for various CLI utility tools"; then diff --git a/local/bin/allsync b/local/bin/allsync index 6e537e2..9539f0d 100755 --- a/local/bin/allsync +++ b/local/bin/allsync @@ -8,17 +8,17 @@ notify_bar() { i3_astroid() { pkill -0 astroid || return 0 - find "/run/user/$(id -u)/i3" "/tmp/i3-$(id -un)".* -name ipc-socket\* 2>/dev/null | \ + find "/run/user/$(id -u)/i3" "/tmp/i3-$(id -un)".* -name ipc-socket\* 2>/dev/null | while read -r socket; do i3-msg -s "$socket" "exec astroid $*" - done + done } cron_enable() { pass mail/cynerd@email.cz >/dev/null # Cache keys if command -v crontab >/dev/null; then { - crontab -l + crontab -l echo "$cronline" } | crontab - else @@ -46,33 +46,33 @@ cron_enabled() { if [ "$#" -gt 0 ]; then case "$1" in - enable) - cron_enable - ;; - disable) + enable) + cron_enable + ;; + disable) + cron_disable + ;; + enabled) + cron_enabled + ;; + state) + if cron_enabled; then + echo "Enabled" + else + echo "Disabled" + fi + ;; + toggle) + if cron_enabled; then cron_disable - ;; - enabled) - cron_enabled - ;; - state) - if cron_enabled; then - echo "Enabled" - else - echo "Disabled" - fi - ;; - toggle) - if cron_enabled; then - cron_disable - else - cron_enable - fi - ;; - *) - echo "${0##*/}: Unknown argument: $1" >&2 - exit 1 - ;; + else + cron_enable + fi + ;; + *) + echo "${0##*/}: Unknown argument: $1" >&2 + exit 1 + ;; esac exit fi @@ -97,7 +97,6 @@ if [ "${ALLSYNC_FLOCK:-n}" != "y" ]; then exit 1 fi - sec() { echo -e '\e[1;34m==========' "$@" '==========\e[0m' } @@ -108,7 +107,6 @@ fail() { ecode=1 } - sec "Passwords" pass git pull || fail "Passwords pull failed" pass git push || fail "Passwords push failed" diff --git a/local/bin/project-test b/local/bin/project-test index e8c6261..feab447 100755 --- a/local/bin/project-test +++ b/local/bin/project-test @@ -15,21 +15,21 @@ print_help() { while [ -n "$1" ]; do case $1 in - -r|--ref) - shift - REF=$1 - ;; - -c|--count) - shift - REF=HEAD~$1 - ;; - --) - shift - break - ;; - *) - break - ;; + -r | --ref) + shift + REF=$1 + ;; + -c | --count) + shift + REF=HEAD~$1 + ;; + --) + shift + break + ;; + *) + break + ;; esac shift done diff --git a/utils/ask b/utils/ask new file mode 100644 index 0000000..4b47c7e --- /dev/null +++ b/utils/ask @@ -0,0 +1,24 @@ +# vim: ft=sh + +# Ask if given section should be installed +# First argument is name (take care not to use special characters for regulard +# expression) and second argument is a question +ask() { + local ignore_file + ignore_file=".ignore-$(hostname)" + [ -f "$ignore_file" ] && grep -q "^$1$" "$ignore_file" && return 1 + if $FORCE; then + echo "\e[1;34m$2\e[0m" + # Fall trough with 0 exit (always yes) + else + echo -e -n "\e[1;34m$2? (Y/n) \e[0m" + local reply + read -r reply + echo "$reply" | grep -qE '^[Yy]?$' + fi +} + +# Check if command is available +hascmd() { + command -v "$1" >/dev/null 2>&1 +} diff --git a/utils/guix b/utils/guix new file mode 100644 index 0000000..bbfb8e5 --- /dev/null +++ b/utils/guix @@ -0,0 +1,16 @@ +# Functions used for interactive installation of new changes to running system +# vim: ft=sh + +guix_install() { + local installed + installed="$(guix package --list-installed)" + local -a toinstall + for pkg in "$@"; do + if awk -v ec=0 -v "PKG=$pkg" '$1 == PKG { ec = 1; } END { exit ec; }' <<<"$installed"; then + toinstall+=("$pkg") + fi + done + if [[ "${#toinstall[@]}" -gt 0 ]]; then + guix install "${toinstall[@]}" + fi +} @@ -1,45 +1,29 @@ # Functions used for interactive installation of new changes to running system # vim: ft=sh -# Ask if given section should be installed -# First argument is name (take care not to use special characters for regulard -# expression) and second argument is a question -ask() { - local ignore_file=".ignore-$(hostname)" - [ -f "$ignore_file" ] && grep -q "^$1$" "$ignore_file" && return 1 - if $FORCE; then - echo "\e[1;34m$2\e[0m" - # Fall trough with 0 exit (always yes) - else - echo -e -n "\e[1;34m$2? (Y/n) \e[0m" - local reply - read -r reply - echo "$reply" | grep -qE '^[Yy]?$' - fi -} - dodiff() { + local out if [ -d "$2" ]; then # If we just copying some file to directory - OUT=$2/$(basename "$1") + out="$2/$(basename "$1")" else - OUT=$2 + out="$2" fi - if ! [ -f "$OUT" ]; then - echo -e "\e[1;33mNot installed:\e[0m $1 => $OUT" + if ! [ -f "$out" ]; then + echo -e "\e[1;33mNot installed:\e[0m $1 => $out" if ask "Install?"; then - doinst "$1" "$OUT" + doinst "$1" "$out" fi return fi - if cmp "$1" "$OUT" >/dev/null 2>&1; then - echo -e "\e[1;32mNo difference detected:\e[0m $OUT" + if cmp "$1" "$out" >/dev/null 2>&1; then + echo -e "\e[1;32mNo difference detected:\e[0m $out" return fi if $FORCE; then - doinst "$1" "$OUT" + doinst "$1" "$out" else - nvim -d "$1" "$OUT" + nvim -d "$1" "$out" fi } @@ -48,11 +32,12 @@ dodiff() { # commands not on deployed tree but on tree in this repository, so we need specify # work tree on command line every time we want target deployed work tree. gitrepo_relink() { - local GITD="gitdir: $PWD/.git$(sed "s/^gitdir: [./]*git//" "$1")" + local gitdir + gitdir="gitdir: $PWD/.git$(sed "s/^gitdir: [./]*git//" "$1")" # We check that we are pointing to correct path just because of making message correct - if ! grep -q "$GITD" "$2"; then + if ! grep -q "$gitdir" "$2"; then echo -e "\e[1;34mPointing git repository $2 to this repository\e[0m" - echo "$GITD" > "$2" + echo "$gitdir" >"$2" fi # else probably not a git repository or who knows. } @@ -69,12 +54,12 @@ checkdiff() { exit 1 fi # Got trough all files ignoring git repositories - for f in `find "$1" \( -type d -exec test -e '{}'/.git \; \) -prune -o -type f -print`; do + for f in $(find "$1" \( -type d -exec test -e '{}'/.git \; \) -prune -o -type f -print); do F="${f#$1}" dodiff "$1/$F" "$2/$F" done # Check if we have all directories ignoring those in git repositories - for d in `find "$1" -type d -print -exec test -e '{}'/.git \; -prune`; do + for d in $(find "$1" -type d -print -exec test -e '{}'/.git \; -prune); do D="${d#$1}" if [ ! -d "$2/$D" ]; then echo -e "\e[1;33mDirectory not installed:\e[0m $1/$D => $2/$D" @@ -84,7 +69,7 @@ checkdiff() { fi done # Now checkout git repositories - for g in `find "$1" -type d -exec test -e '{}'/.git \; -print -prune`; do + for g in $(find "$1" -type d -exec test -e '{}'/.git \; -print -prune); do G="$2/${g#$1}" gitrepo_relink "$g/.git" "$G/.git" # Always reling .git just to be sure PREV="$(pwd)" @@ -111,13 +96,13 @@ doinst() { mkdir -p "$(dirname "$2")" rsync -rlpt $1 $2 # Now edit all .git files in target directory - for g in `find "$1" -name '.git' -type f`; do + for g in $(find "$1" -name '.git' -type f); do gitrepo_relink "$g" "$2/${g#$1}" done } inst() { - if [ ! -e "$1" ]; then + if [ ! -e "$1" ]; then echo "Missing file to be installed: $1" >&2 fi if [ -e "$2" ]; then |
