diff --git a/home/user/.local/bin/slm b/home/user/.local/bin/slm new file mode 100755 index 0000000..43d73c3 --- /dev/null +++ b/home/user/.local/bin/slm @@ -0,0 +1,62 @@ +#!/bin/bash + +LAYOUTS_DIR="$HOME/.screenlayout" + + +_die() { + echo "$0: $1" >&2 + exit $2 +} + +test -d "$LAYOUTS_DIR" || (mkdir "$LAYOUTS_DIR" && touch "$LAYOUTS_DIR/default.sh") + + +die_if_invalid_path() { + if [[ "$1" =~ ".." ]]; then + die "Path can\`t contains '..'" 3 + fi + + if [[ "$1" = /* ]]; then + die "Path can\`t start from '/'" 3 + fi +} + + +cmd_list() { + ls "$LAYOUTS_DIR" +} + +cmd_edit() { + die_if_invalid_path "$1" + $EDITOR "$LAYOUTS_DIR/$1.sh" + chmod u+x "$LAYOUTS_DIR/$1.sh" +} + +cmd_load() { + if [ -z "$1" ]; then + "$LAYOUTS_DIR/default.sh" + return 0 + fi + + "$LAYOUTS_DIR/$1.sh" +} + +cmd_wallpaper() { + local wallpapers="$HOME/.wallpaper" + feh --no-fehbg --bg-scale "$wallpapers/$(ls "$wallpapers" | shuf -n 1)" +} + +cmd_help () { + echo "slm (ls|add|load|wallpaper)" >&2 +} + + +case "$1" in + ls) shift; cmd_list "$@" ;; + add|edit) shift; cmd_edit "$@" ;; + load) shift; cmd_load "$@" ;; + wallpaper) shift; cmd_wallpaper "$@" ;; + *) shift; cmd_help "$@" ;; +esac +exit 0 + diff --git a/install b/install index 72f18d4..7180d1c 100755 --- a/install +++ b/install @@ -15,7 +15,7 @@ declare -A TARGETS=( ["nvim"]=".config/nvim .local/bin/vim_askpass_helper .local/bin/vim_askpass_helper_python" ["git"]=".gitconfig .githooks .gitignore" ["ranger"]=".config/ranger" - ["i3"]=".config/i3 .config/i3status .local/bin/i3status_wrapper .config/picom" + ["i3"]=".config/i3 .config/i3status .local/bin/i3status_wrapper .config/picom .local/bin/slm" ["bat"]=".config/bat" ["psql"]=".psqlrc" ["docker"]=".docker/cli-plugins"