mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
refactor: expose all scripts as modules
This commit is contained in:
parent
db231d4b83
commit
8f4fe686a5
29 changed files with 785 additions and 330 deletions
56
scripts/check.sh
Normal file
56
scripts/check.sh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
kitty=0
|
||||
element=0
|
||||
discord=0
|
||||
spotifyplayer=0
|
||||
while :; do
|
||||
case ${1:-} in
|
||||
-k|--kitty) kitty=1
|
||||
;;
|
||||
-e|--element) element=1
|
||||
;;
|
||||
-d|--discord) discord=1
|
||||
;;
|
||||
-s|--spotifyplayer) spotifyplayer=1
|
||||
;;
|
||||
*) break
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $kitty -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep kittyterm || true)
|
||||
CHECK=$(swaymsg -t get_tree | grep kittyterm || true)
|
||||
if [ "$CHECK" == "" ]; then
|
||||
exec kitty -T kittyterm & sleep 1
|
||||
fi
|
||||
if [ "$STR" == "" ]; then
|
||||
exec swaymsg '[title="kittyterm"]' scratchpad show
|
||||
else
|
||||
exec swaymsg '[title="kittyterm"]' scratchpad show
|
||||
fi
|
||||
elif [[ $element -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | grep Element || true)
|
||||
if [ "$STR" == "" ]; then
|
||||
exec element-desktop
|
||||
else
|
||||
exec swaymsg '[app_id=Element]' kill
|
||||
fi
|
||||
elif [[ $discord -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | grep discord || true)
|
||||
if [ "$STR" == "" ]; then
|
||||
exec discord
|
||||
else
|
||||
exec swaymsg '[app_id=discord]' kill
|
||||
fi
|
||||
elif [[ $spotifyplayer -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep spotifytui || true)
|
||||
CHECK=$(swaymsg -t get_tree | grep spotifytui || true)
|
||||
if [ "$CHECK" == "" ]; then
|
||||
exec kitty -T spotifytui -o confirm_os_window_close=0 spotify_player & sleep 1
|
||||
fi
|
||||
if [ "$STR" == "" ]; then
|
||||
exec swaymsg '[title="spotifytui"]' scratchpad show
|
||||
else
|
||||
exec swaymsg '[title="spotifytui"]' scratchpad show
|
||||
fi
|
||||
fi
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
# Adapted from https://github.com/bennofs/nix-index/blob/master/command-not-found.sh
|
||||
|
||||
command_not_found_handle () {
|
||||
if [ -n "${MC_SID-}" ] || ! [ -t 1 ]; then
|
||||
>&2 echo "$1: command not found"
|
||||
|
|
@ -9,7 +8,7 @@ command_not_found_handle () {
|
|||
echo -n "searching nix-index..."
|
||||
ATTRS=$(@nix-locate@ --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$1")
|
||||
|
||||
case `echo -n "$ATTRS" | grep -c "^"` in
|
||||
case $(echo -n "$ATTRS" | grep -c "^") in
|
||||
0)
|
||||
>&2 echo -ne "$(@tput@ el1)\r"
|
||||
>&2 echo "$1: command not found"
|
||||
|
|
@ -18,8 +17,8 @@ command_not_found_handle () {
|
|||
>&2 echo -ne "$(@tput@ el1)\r"
|
||||
>&2 echo "The program ‘$(@tput@ setaf 4)$1$(@tput@ sgr0)’ is currently not installed."
|
||||
>&2 echo "It is provided by the following derivation(s):"
|
||||
while read ATTR; do
|
||||
ATTR=$(echo "$ATTR" | sed 's|\.out$||') # Strip trailing '.out'
|
||||
while read -r ATTR; do
|
||||
ATTR=${ATTR%.out}
|
||||
>&2 echo " $(@tput@ setaf 12)nixpkgs#$(@tput@ setaf 4)$ATTR$(@tput@ sgr0)"
|
||||
done <<< "$ATTRS"
|
||||
esac
|
||||
|
|
@ -28,6 +27,6 @@ command_not_found_handle () {
|
|||
}
|
||||
|
||||
command_not_found_handler () {
|
||||
command_not_found_handle $@
|
||||
command_not_found_handle "$@"
|
||||
return $?
|
||||
}
|
||||
|
|
|
|||
22
scripts/e.sh
Normal file
22
scripts/e.sh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
wait=0
|
||||
while :; do
|
||||
case ${1:-} in
|
||||
-w|--wait) wait=1
|
||||
;;
|
||||
*) break
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep kittyterm || true )
|
||||
if [ "$STR" == "" ]; then
|
||||
swaymsg '[title="kittyterm"]' scratchpad show
|
||||
emacsclient -c -a "" "$@"
|
||||
swaymsg '[title="kittyterm"]' scratchpad show
|
||||
else
|
||||
if [[ $wait -eq 0 ]]; then
|
||||
emacsclient -n -c -a "" "$@"
|
||||
else
|
||||
emacsclient -c -a "" "$@"
|
||||
fi
|
||||
fi
|
||||
13
scripts/editor-wait.sh
Normal file
13
scripts/editor-wait.sh
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep kittyterm || true )
|
||||
if [ "$STR" == "" ]; then
|
||||
VAR="1"
|
||||
swaymsg '[title="kittyterm"]' scratchpad show
|
||||
else
|
||||
VAR="0"
|
||||
fi
|
||||
emacsclient -c -a "" "$@" # open emacs in a new frame, start new daemon if it is dead and open arg
|
||||
if [ "$VAR" == "1" ]
|
||||
then
|
||||
swaymsg '[title="kittyterm"]' scratchpad show
|
||||
fi
|
||||
exit 0
|
||||
5
scripts/opacitytoggle.sh
Normal file
5
scripts/opacitytoggle.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
if swaymsg opacity plus 0.01 -q; then
|
||||
swaymsg opacity 1
|
||||
else
|
||||
swaymsg opacity 0.95
|
||||
fi
|
||||
24
scripts/pass-fuzzel-otp.sh
Normal file
24
scripts/pass-fuzzel-otp.sh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
shopt -s nullglob globstar
|
||||
|
||||
typeit=0
|
||||
if [[ $# -ge 1 && $1 == "--type" ]]; then
|
||||
typeit=1
|
||||
shift
|
||||
fi
|
||||
|
||||
export PASSWORD_STORE_DIR=~/.local/share/password-store
|
||||
prefix=${PASSWORD_STORE_DIR-~/.local/share/password-store}
|
||||
password_files=( "$prefix"/otp/**/*.gpg )
|
||||
password_files=( "${password_files[@]#"$prefix"/}" )
|
||||
password_files=( "${password_files[@]%.gpg}" )
|
||||
|
||||
password=$(printf '%s\n' "${password_files[@]}" | fuzzel --dmenu "$@")
|
||||
|
||||
[[ -n $password ]] || exit
|
||||
|
||||
if [[ $typeit -eq 0 ]]; then
|
||||
pass otp -c "$password" &>/tmp/pass-fuzzel
|
||||
else
|
||||
pass otp "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
|
||||
fi
|
||||
notify-send -u critical -a pass -t 1000 "Copied/Typed OTPassword"
|
||||
43
scripts/pass-fuzzel.sh
Normal file
43
scripts/pass-fuzzel.sh
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Adapted from https://code.kulupu.party/thesuess/home-manager/src/branch/main/modules/river.nix
|
||||
shopt -s nullglob globstar
|
||||
|
||||
otp=0
|
||||
typeit=0
|
||||
while :; do
|
||||
case ${1:-} in
|
||||
-t|--type) typeit=1
|
||||
;;
|
||||
-o|--otp) otp=1
|
||||
;;
|
||||
*) break
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
export PASSWORD_STORE_DIR=~/.local/share/password-store
|
||||
prefix=${PASSWORD_STORE_DIR-~/.local/share/password-store}
|
||||
if [[ $otp -eq 0 ]]; then
|
||||
password_files=( "$prefix"/**/*.gpg )
|
||||
else
|
||||
password_files=( "$prefix"/otp/**/*.gpg )
|
||||
fi
|
||||
password_files=( "${password_files[@]#"$prefix"/}" )
|
||||
password_files=( "${password_files[@]%.gpg}" )
|
||||
|
||||
password=$(printf '%s\n' "${password_files[@]}" | fuzzel --dmenu "$@")
|
||||
|
||||
[[ -n $password ]] || exit
|
||||
if [[ $otp -eq 0 ]]; then
|
||||
if [[ $typeit -eq 0 ]]; then
|
||||
pass show -c "$password" &>/tmp/pass-fuzzel
|
||||
else
|
||||
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
|
||||
fi
|
||||
else
|
||||
if [[ $typeit -eq 0 ]]; then
|
||||
pass otp -c "$password" &>/tmp/pass-fuzzel
|
||||
else
|
||||
pass otp "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
|
||||
fi
|
||||
fi
|
||||
notify-send -u critical -a pass -t 1000 "Copied/Typed Password"
|
||||
56
scripts/swarselcheck.sh
Normal file
56
scripts/swarselcheck.sh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
kitty=0
|
||||
element=0
|
||||
discord=0
|
||||
spotifyplayer=0
|
||||
while :; do
|
||||
case ${1:-} in
|
||||
-k|--kitty) kitty=1
|
||||
;;
|
||||
-e|--element) element=1
|
||||
;;
|
||||
-d|--discord) discord=1
|
||||
;;
|
||||
-s|--spotifyplayer) spotifyplayer=1
|
||||
;;
|
||||
*) break
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $kitty -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep kittyterm || true)
|
||||
CHECK=$(swaymsg -t get_tree | grep kittyterm || true)
|
||||
if [ "$CHECK" == "" ]; then
|
||||
exec kitty -T kittyterm & sleep 1
|
||||
fi
|
||||
if [ "$STR" == "" ]; then
|
||||
exec swaymsg '[title="kittyterm"]' scratchpad show
|
||||
else
|
||||
exec swaymsg '[title="kittyterm"]' scratchpad show
|
||||
fi
|
||||
elif [[ $element -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | grep Element || true)
|
||||
if [ "$STR" == "" ]; then
|
||||
exec element-desktop
|
||||
else
|
||||
exec swaymsg '[app_id=Element]' kill
|
||||
fi
|
||||
elif [[ $discord -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | grep discord || true)
|
||||
if [ "$STR" == "" ]; then
|
||||
exec discord
|
||||
else
|
||||
exec swaymsg '[app_id=discord]' kill
|
||||
fi
|
||||
elif [[ $spotifyplayer -eq 1 ]]; then
|
||||
STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep spotifytui || true)
|
||||
CHECK=$(swaymsg -t get_tree | grep spotifytui || true)
|
||||
if [ "$CHECK" == "" ]; then
|
||||
exec kitty -T spotifytui -o confirm_os_window_close=0 spotify_player & sleep 1
|
||||
fi
|
||||
if [ "$STR" == "" ]; then
|
||||
exec swaymsg '[title="spotifytui"]' scratchpad show
|
||||
else
|
||||
exec swaymsg '[title="spotifytui"]' scratchpad show
|
||||
fi
|
||||
fi
|
||||
24
scripts/waybarupdate.sh
Normal file
24
scripts/waybarupdate.sh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
CFG=$(git --git-dir="$HOME"/.dotfiles/.git --work-tree="$HOME"/.dotfiles/ status -s | wc -l)
|
||||
CSE=$(git --git-dir="$HOME"/Documents/GitHub/CSE_TUWIEN/.git --work-tree="$HOME"/Documents/GitHub/CSE_TUWIEN/ status -s | wc -l)
|
||||
PASS=$(( $(git --git-dir="$HOME"/.local/share/password-store/.git --work-tree="$HOME"/.local/share/password-store/ status -s | wc -l) + $(git --git-dir="$HOME"/.local/share/password-store/.git --work-tree="$HOME"/.local/share/password-store/ diff origin/main..HEAD | wc -l) ))
|
||||
|
||||
if [[ $CFG != 0 ]]; then
|
||||
CFG_STR='CONFIG'
|
||||
else
|
||||
CFG_STR=''
|
||||
fi
|
||||
|
||||
if [[ $CSE != 0 ]]; then
|
||||
CSE_STR=' CSE'
|
||||
else
|
||||
CSE_STR=''
|
||||
fi
|
||||
|
||||
if [[ $PASS != 0 ]]; then
|
||||
PASS_STR=' PASS'
|
||||
else
|
||||
PASS_STR=''
|
||||
fi
|
||||
|
||||
OUT="$CFG_STR""$CSE_STR""$PASS_STR"
|
||||
echo "$OUT"
|
||||
Loading…
Add table
Add a link
Reference in a new issue