sh compatible
This commit is contained in:
parent
1706e7bda9
commit
2dd8b6d5a7
12
README.md
12
README.md
@ -63,17 +63,5 @@ Per-user dotfiles "package" manager
|
||||
4. Transaction based installation
|
||||
5. Does not overwrite your configs
|
||||
|
||||
### Dependencies
|
||||
* bash
|
||||
* coreutils
|
||||
* diffutils
|
||||
* grep
|
||||
|
||||
|
||||
### Optional dependencies
|
||||
* git
|
||||
* wget
|
||||
* unzip
|
||||
|
||||
|
||||
<h1 align="center"><a href="#top">▲</a></h1>
|
||||
@ -1,65 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
LAYOUTS_DIR="$HOME/.screenlayout"
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
_die() {
|
||||
echo "$0: $1" >&2
|
||||
exit $2
|
||||
}
|
||||
set -eu
|
||||
|
||||
test -d "$LAYOUTS_DIR" || (mkdir "$LAYOUTS_DIR" && touch "$LAYOUTS_DIR/default.sh")
|
||||
readonly LAYOUTS_DIR="${HOME}/.screenlayout"
|
||||
|
||||
|
||||
die_if_invalid_path() {
|
||||
if [[ -z "$1" ]]; then
|
||||
_die "Blank name"
|
||||
fi
|
||||
|
||||
if [[ "$1" =~ ".." ]]; then
|
||||
_die "Path can\`t contains '..'" 3
|
||||
fi
|
||||
|
||||
if [[ "$1" = /* ]]; then
|
||||
_die "Path can\`t start from '/'" 3
|
||||
fi
|
||||
}
|
||||
|
||||
if [ ! -d "${LAYOUTS_DIR}" ]; then
|
||||
mkdir "${LAYOUTS_DIR}"
|
||||
fi
|
||||
|
||||
cmd_list() {
|
||||
find "$LAYOUTS_DIR" -type f,l -exec basename -s .sh {} \;
|
||||
}
|
||||
|
||||
cmd_edit() {
|
||||
die_if_invalid_path "$1"
|
||||
$EDITOR "$LAYOUTS_DIR/$1.sh"
|
||||
chmod u+x "$LAYOUTS_DIR/$1.sh"
|
||||
find "$LAYOUTS_DIR" -type f,l -exec basename {} \;
|
||||
}
|
||||
|
||||
cmd_wallpaper() {
|
||||
local wallpapers="$HOME/.wallpaper"
|
||||
feh --no-fehbg --bg-scale "$wallpapers/$(ls "$wallpapers" | shuf -n 1)"
|
||||
readonly wallpapers="${HOME}/.wallpaper"
|
||||
feh --no-fehbg --bg-scale "$(find "${wallpapers}" | shuf -n 1)"
|
||||
}
|
||||
|
||||
cmd_load() {
|
||||
if [ -z "$1" ]; then
|
||||
"$LAYOUTS_DIR/default.sh"
|
||||
if [ -z "${1:-}" ]; then
|
||||
"${LAYOUTS_DIR}/default"
|
||||
else
|
||||
"$LAYOUTS_DIR/$1.sh"
|
||||
"${LAYOUTS_DIR}/${1}"
|
||||
fi
|
||||
cmd_wallpaper
|
||||
}
|
||||
|
||||
cmd_help () {
|
||||
echo "slm (ls|add|load|wallpaper)" >&2
|
||||
echo "slm (ls|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
|
||||
exit 0
|
||||
Loading…
x
Reference in New Issue
Block a user