about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-02-20 15:38:30 +0100
committerSoispha <soispha@vhack.eu>2024-02-20 15:50:32 +0100
commit1f56d6d1f4292c807b470b753fece696a2582e7e (patch)
treef0f8647699195494cc5cd89f0d80a6c9b187e66d
parentbuild(flake): Add treefmt (diff)
downloadnixos-config-1f56d6d1f4292c807b470b753fece696a2582e7e.tar.gz
nixos-config-1f56d6d1f4292c807b470b753fece696a2582e7e.zip
refactor(hm/conf/zsh/config): Rework old config scripts
-rw-r--r--hm/soispha/conf/zsh/config/command_not_found_insult.sh (renamed from hm/soispha/conf/zsh/config/command_not_found_insult.zsh)31
-rw-r--r--hm/soispha/conf/zsh/config/custom_cursor.zsh (renamed from hm/soispha/conf/zsh/config/custom_cursor.sh)4
-rw-r--r--hm/soispha/conf/zsh/config/zsh-init.zsh (renamed from hm/soispha/conf/zsh/config/zsh-init.sh)4
-rw-r--r--hm/soispha/conf/zsh/config/zsh-prompt.sh63
-rw-r--r--hm/soispha/conf/zsh/config/zsh-prompt.zsh64
5 files changed, 84 insertions, 82 deletions
diff --git a/hm/soispha/conf/zsh/config/command_not_found_insult.zsh b/hm/soispha/conf/zsh/config/command_not_found_insult.sh
index 22317a19..5126845a 100644
--- a/hm/soispha/conf/zsh/config/command_not_found_insult.zsh
+++ b/hm/soispha/conf/zsh/config/command_not_found_insult.sh
@@ -1,11 +1,11 @@
 #! /usr/bin/env bash
-print_message () {
+print_message() {
 
     local messages
     local message
 
     ### STANDARD INSULTS ###
-    declare -a array1=(
+    declare -a _array1=(
         "(╯°□°)╯︵ ┻━┻"
         "¯\_(ツ)_/¯"
         "ACHTUNG! ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN."
@@ -210,7 +210,7 @@ print_message () {
         "You are idiots and swine."
         "Every letter of yours breathes Moabitish pride. So much can a single bull inflate a single bubble that you practically make distinguished asses into gods."
         "You sophistic worms, grasshoppers, locusts, frogs and lice!"
-        "You completely close your mind and do nothing but shout, \"Anathema, anathema, anathema!\" so that by your own voice you are judged mad."
+        'You completely close your mind and do nothing but shout, "Anathema, anathema, anathema!" so that by your own voice you are judged mad.'
         "Let this generation of vipers prepare itself for unquenchable fire!"
         "You rush forward as an ass under the pelt of a lion."
         "In appearance and words you simulate modesty, but you are so swollen with haughtiness, arrogance, pride, malice, villainy, rashness, superciliousness, ignorance, and stupidity that there is nothing to surpass you."
@@ -225,25 +225,25 @@ print_message () {
     )
 
     # If CMD_NOT_FOUND_MSGS array is populated use those messages instead of the defaults
-    [[ -n ${CMD_NOT_FOUND_MSGS} ]] && messages=( "${CMD_NOT_FOUND_MSGS[@]}" )
+    [[ -n ${CMD_NOT_FOUND_MSGS} ]] && messages=("${CMD_NOT_FOUND_MSGS[@]}")
 
     # If CMD_NOT_FOUND_MSGS_APPEND array is populated append those to the existing messages
-    [[ -n ${CMD_NOT_FOUND_MSGS_APPEND} ]] && messages+=( "${CMD_NOT_FOUND_MSGS_APPEND[@]}" )
+    [[ -n ${CMD_NOT_FOUND_MSGS_APPEND} ]] && messages+=("${CMD_NOT_FOUND_MSGS_APPEND[@]}")
 
     # Seed RANDOM with an integer of some length
-    RANDOM=$(od -vAn -N4 -tu < /dev/urandom)
+    RANDOM=$(od -vAn -N4 -tu </dev/urandom)
 
     # Print a randomly selected message, but only about half the time to annoy the user a
     # little bit less.
     if [[ $((RANDOM % 2)) -lt 1 ]]; then
-        message=${messages[${RANDOM} % ${#messages[@]}]}
-        printf "\n  $(tput bold)$(tput setaf 1)${message}$(tput sgr0)\n\n" >&2
+        message=${messages[RANDOM % ${#messages[@]}]}
+        printf "\n  %s%s%s\n\n" "$(tput bold)$(tput setaf 1)" "$message" "$(tput sgr0)" >&2
     fi
 }
 
-function_exists () {
+function_exists() {
     # Zsh returns 0 even on non existing functions with -F so use -f
-    declare -f "$1" > /dev/null
+    declare -f "$1" >/dev/null
     return $?
 }
 
@@ -267,18 +267,17 @@ if function_exists command_not_found_handler; then
         eval "orig_$(declare -f command_not_found_handler)"
     fi
 else
-    orig_command_not_found_handler () {
+    orig_command_not_found_handler() {
         printf "zsh: command not found: %s\n" "$1" >&2
         return 127
     }
 fi
 
-command_not_found_handler () {
+command_not_found_handler() {
     print_message
     orig_command_not_found_handler "$@"
 }
 
-
 #
 # Bash
 #
@@ -287,15 +286,13 @@ if function_exists command_not_found_handle; then
         eval "orig_$(declare -f command_not_found_handle)"
     fi
 else
-    orig_command_not_found_handle () {
+    orig_command_not_found_handle() {
         printf "%s: %s: command not found\n" "$0" "$1" >&2
         return 127
     }
 fi
 
-command_not_found_handle () {
+command_not_found_handle() {
     print_message
     orig_command_not_found_handle "$@"
 }
-
-
diff --git a/hm/soispha/conf/zsh/config/custom_cursor.sh b/hm/soispha/conf/zsh/config/custom_cursor.zsh
index 9a6da012..37390c1c 100644
--- a/hm/soispha/conf/zsh/config/custom_cursor.sh
+++ b/hm/soispha/conf/zsh/config/custom_cursor.zsh
@@ -1,3 +1,5 @@
+#!/usr/bin/env zsh
+
 # Change cursor shape for different vi modes.
 function zle-keymap-select {
   if [[ ${KEYMAP} == vicmd ]] ||
@@ -17,7 +19,7 @@ autoload -U select-quoted
 zle -N select-quoted
 for m in visual viopp; do
   for c in {a,i}{\',\",\`}; do
-    bindkey -M $m $c select-quoted
+    bindkey -M "$m" "$c" select-quoted
   done
 done
 
diff --git a/hm/soispha/conf/zsh/config/zsh-init.sh b/hm/soispha/conf/zsh/config/zsh-init.zsh
index a19f3eff..cd8d34a9 100644
--- a/hm/soispha/conf/zsh/config/zsh-init.sh
+++ b/hm/soispha/conf/zsh/config/zsh-init.zsh
@@ -1,3 +1,4 @@
+#!/usr/bin/env zsh
 # If not running interactively, don't do anything
 [[ $- != *i* ]] && return
 
@@ -10,7 +11,8 @@
 #autoload -Uz colors && colors
 #autoload -Uz compinit && compinit -u
 ## Edit line in vim buffer ctrl-v
-autoload -Uz edit-command-line; zle -N edit-command-line
+autoload -Uz edit-command-line
+zle -N edit-command-line
 ## Enter vim buffer from normal mode
 #autoload -Uz edit-command-line && zle -N edit-command-line
 bindkey "^V" edit-command-line
diff --git a/hm/soispha/conf/zsh/config/zsh-prompt.sh b/hm/soispha/conf/zsh/config/zsh-prompt.sh
deleted file mode 100644
index 26d478ef..00000000
--- a/hm/soispha/conf/zsh/config/zsh-prompt.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-#vim:ft=zsh
-_command_time_preexec() {
-    timer=${timer:-$SECONDS}
-}
-
-_command_time_precmd() {
-    PROMPT_TMP_DIR=$(mktemp)
-  if [ $timer ]; then
-    ts=$(($SECONDS - $timer))
-    tts=$ts
-    mi=0
-    ho=0
-    if [ $ts -ge 3 ];then
-        while [ $ts -ge 60 ];do
-            ts=$((ts-60))
-            mi=$((mi+1))
-        done
-
-        while [ $mi -ge 60 ];do
-            mi=$((mi-60))
-            ho=$((ho+1))
-        done
-
-        if [ $tts -ge 3600 ];then
-            out=$(printf '%dh %dm %ds\n' $ho $mi $ts)
-        elif [ $tts -ge 60 ];then
-            out=$(printf '%dm %ds\n' $mi $ts)
-        elif [ $tts -lt 60 ];then
-             out=$(printf '%ds\n' $ts)
-        fi
-
-    export psvar[1]="took $(printf '%s ' "$out")"
-    echo $psvar[1] > $PROMPT_TMP_DIR
-    fi
-
-    unset timer
-    unset ts
-    unset tts
-    unset mi
-    unset ho
-fi
-}
-
-_command_ro_precmd() {
-if ! [ -w $(pwd) ];then
-    echo " "
-fi
-}
-
-preexec_functions+=(_command_time_preexec)
-precmd_functions+=(_command_time_precmd)
-
-blue="14"
-red="9"
-white="15"
-setopt PROMPT_SUBST
-export PROMPT='%(?.%F{$blue}.%F{$red})%B%3~%(!. %F{$red}as root %f. )%F{$white}$(if [ -n $PROMPT_TMP_DIR ];then cat $PROMPT_TMP_DIR 2>/dev/null; rm $PROMPT_TMP_DIR 2>/dev/null;fi)%f%(?.%F{$blue}.%F{$red})%F{$red}$(_command_ro_precmd)%F{$blue}❯ %b%f'
-export RPROMPT=''
-
-#%(2V.%F{$red}%2v%f$(export psvar[2]="") .)
-
-# TODO::
-# Add git support
diff --git a/hm/soispha/conf/zsh/config/zsh-prompt.zsh b/hm/soispha/conf/zsh/config/zsh-prompt.zsh
new file mode 100644
index 00000000..8f5238b2
--- /dev/null
+++ b/hm/soispha/conf/zsh/config/zsh-prompt.zsh
@@ -0,0 +1,64 @@
+#!/usr/bin/env zsh
+_command_time_preexec() {
+    timer=${timer:-$SECONDS}
+}
+
+_command_time_precmd() {
+    PROMPT_TMP_DIR=$(mktemp)
+    if [ $timer ]; then
+        ts=$((SECONDS - timer))
+        tts=$ts
+        mi=0
+        ho=0
+        if [ $ts -ge 3 ]; then
+            while [ $ts -ge 60 ]; do
+                ts=$((ts - 60))
+                mi=$((mi + 1))
+            done
+
+            while [ $mi -ge 60 ]; do
+                mi=$((mi - 60))
+                ho=$((ho + 1))
+            done
+
+            if [ $tts -ge 3600 ]; then
+                out=$(printf '%dh %dm %ds\n' $ho $mi $ts)
+            elif [ $tts -ge 60 ]; then
+                out=$(printf '%dm %ds\n' $mi $ts)
+            elif [ $tts -lt 60 ]; then
+                out=$(printf '%ds\n' $ts)
+            fi
+
+            export psvar[1]="took $(printf '%s ' "$out")"
+            echo $psvar[1] >$PROMPT_TMP_DIR
+        fi
+
+        unset timer
+        unset ts
+        unset tts
+        unset mi
+        unset ho
+    fi
+}
+
+_command_ro_precmd() {
+    if ! [ -w $(pwd) ]; then
+        echo " "
+    fi
+}
+
+preexec_functions+=(_command_time_preexec)
+precmd_functions+=(_command_time_precmd)
+
+blue="14"
+red="9"
+white="15"
+setopt PROMPT_SUBST
+export PROMPT='%(?.%F{$blue}.%F{$red})%B%3~%(!. %F{$red}as root %f. )%F{$white}$(if [ -n $PROMPT_TMP_DIR ];then cat $PROMPT_TMP_DIR 2>/dev/null; rm $PROMPT_TMP_DIR 2>/dev/null;fi)%f%(?.%F{$blue}.%F{$red})%F{$red}$(_command_ro_precmd)%F{$blue}❯ %b%f'
+export RPROMPT=''
+
+#%(2V.%F{$red}%2v%f$(export psvar[2]="") .)
+
+# TODO::
+# Add git support
+#vim:ft=zsh