sh compatible

This commit is contained in:
thek4n 2024-11-04 04:14:21 +03:00
parent 1706e7bda9
commit 2dd8b6d5a7
2 changed files with 14 additions and 49 deletions

View File

@ -63,17 +63,5 @@ Per-user dotfiles "package" manager
4. Transaction based installation 4. Transaction based installation
5. Does not overwrite your configs 5. Does not overwrite your configs
### Dependencies
* bash
* coreutils
* diffutils
* grep
### Optional dependencies
* git
* wget
* unzip
<h1 align="center"><a href="#top"></a></h1> <h1 align="center"><a href="#top"></a></h1>

View File

@ -1,65 +1,42 @@
#!/bin/bash #!/bin/sh
LAYOUTS_DIR="$HOME/.screenlayout"
_die() { set -eu
echo "$0: $1" >&2
exit $2
}
test -d "$LAYOUTS_DIR" || (mkdir "$LAYOUTS_DIR" && touch "$LAYOUTS_DIR/default.sh") readonly LAYOUTS_DIR="${HOME}/.screenlayout"
die_if_invalid_path() { if [ ! -d "${LAYOUTS_DIR}" ]; then
if [[ -z "$1" ]]; then mkdir "${LAYOUTS_DIR}"
_die "Blank name" fi
fi
if [[ "$1" =~ ".." ]]; then
_die "Path can\`t contains '..'" 3
fi
if [[ "$1" = /* ]]; then
_die "Path can\`t start from '/'" 3
fi
}
cmd_list() { cmd_list() {
find "$LAYOUTS_DIR" -type f,l -exec basename -s .sh {} \; find "$LAYOUTS_DIR" -type f,l -exec basename {} \;
}
cmd_edit() {
die_if_invalid_path "$1"
$EDITOR "$LAYOUTS_DIR/$1.sh"
chmod u+x "$LAYOUTS_DIR/$1.sh"
} }
cmd_wallpaper() { cmd_wallpaper() {
local wallpapers="$HOME/.wallpaper" readonly wallpapers="${HOME}/.wallpaper"
feh --no-fehbg --bg-scale "$wallpapers/$(ls "$wallpapers" | shuf -n 1)" feh --no-fehbg --bg-scale "$(find "${wallpapers}" | shuf -n 1)"
} }
cmd_load() { cmd_load() {
if [ -z "$1" ]; then if [ -z "${1:-}" ]; then
"$LAYOUTS_DIR/default.sh" "${LAYOUTS_DIR}/default"
else else
"$LAYOUTS_DIR/$1.sh" "${LAYOUTS_DIR}/${1}"
fi fi
cmd_wallpaper cmd_wallpaper
} }
cmd_help () { cmd_help () {
echo "slm (ls|add|load|wallpaper)" >&2 echo "slm (ls|load|wallpaper)" >&2
} }
case "$1" in case "$1" in
ls) shift; cmd_list "$@" ;; ls) shift; cmd_list "$@" ;;
add|edit) shift; cmd_edit "$@" ;;
load) shift; cmd_load "$@" ;; load) shift; cmd_load "$@" ;;
wallpaper) shift; cmd_wallpaper "$@" ;; wallpaper) shift; cmd_wallpaper "$@" ;;
*) shift; cmd_help "$@" ;; *) shift; cmd_help "$@" ;;
esac esac
exit 0 exit 0