This commit is contained in:
Tobias Reisinger 2024-01-08 23:37:31 +01:00
commit d6985ded7e
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
18 changed files with 348 additions and 0 deletions

3
.envrc Normal file
View file

@ -0,0 +1,3 @@
use nix
printf '\nPlease set and export $BASHLY_SOURCE_DIR\n\n'

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.target
output/
autostart-manage/lib/send_completions.sh

20
Makefile Normal file
View file

@ -0,0 +1,20 @@
target:
@echo "Enter target directory:"
@read target; \
echo $$target > .target
get-target:
$(eval TARGET := $(shell cat .target))
output-dir:
mkdir -p ./output
generate: get-target output-dir
BASHLY_SOURCE_DIR=$(TARGET) bashly generate
completions: generate
BASHLY_SOURCE_DIR=$(TARGET) bashly add --force completions_script ./output/_$(TARGET)
deploy: completions
cp -f ./output/$(TARGET) ~/.local/bin/
cp -f ./output/_$(TARGET) ~/.config/completionsrc.d/

View file

@ -0,0 +1,99 @@
name: autostart-manage
help: Manage autostart
version: 0.1.0
dependencies:
yq:
command: [tomlq]
help: please install yq (https://github.com/kislyuk/yq)
environment_variables:
- name: HOSTNAME
help: The hostname to use. We will try to get the value automatically.
commands:
- name: completions
help: Generate bash completions
- name: list
help: List available programs
- name: info
help: Get the current status of all programs
- name: sync
help: Remove all programs from autostart and the re-enable all
- name: enable
help: Add a single program to autostart
args:
- name: program
required: true
help: Program to add to autostart
completions:
- $(autostart-manage list)
filename: systemctl.sh
- name: disable
help: Remove a single program from autostart
args:
- name: program
required: true
help: Program to add to autostart
completions:
- $(autostart-manage list)
filename: systemctl.sh
- name: restart
help: Restart programs from autostart
args:
- name: program
help: Program to add to autostart
default: "*"
completions:
- $(autostart-manage list)
filename: systemctl.sh
- name: start
help: Start programs from autostart
args:
- name: program
help: Program to start to autostart
default: "*"
completions:
- $(autostart-manage list)
filename: systemctl.sh
- name: status
help: Check status of programs from autostart
args:
- name: program
help: Program to check status on
default: "*"
completions:
- $(autostart-manage list)
filename: systemctl.sh
- name: stop
help: Stop programs from autostart
args:
- name: program
help: Program to stop
default: "*"
completions:
- $(autostart-manage list)
filename: systemctl.sh
- name: log
help: Show the log for a single program from autostart
args:
- name: program
required: true
help: Program to log
completions:
- $(autostart-manage list)
- name: exec
help: Execute a single program from autostart
args:
- name: program
required: true
help: Program to execute
completions:
- $(autostart-manage list)
- name: run
help: Run all programs
- name: run-wayland
help: Run all the wayland specific tasks and all programs
- name: run-xorg
help: Run all the xorg specific tasks and all programs

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
send_completions

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
program=${args[program]:?}
cmd=$(_get_autostart_cmd "$program")
sleep "$(_get_autostart_delay "$program")"
bash -c "$cmd"

View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
autostart_units=()
while IFS='' read -r line
do
autostart_units+=("$line")
done < <(_list)
_echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command'

View file

@ -0,0 +1,42 @@
## Color functions [@bashly-upgrade colors]
## This file is a part of Bashly standard library
##
## Usage:
## Use any of the functions below to color or format a portion of a string.
##
## echo "before $(red this is red) after"
## echo "before $(green_bold this is green_bold) after"
##
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
fi
}
red() { print_in_color "\e[31m" "$*"; }
green() { print_in_color "\e[32m" "$*"; }
yellow() { print_in_color "\e[33m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }
magenta() { print_in_color "\e[35m" "$*"; }
cyan() { print_in_color "\e[36m" "$*"; }
bold() { print_in_color "\e[1m" "$*"; }
underlined() { print_in_color "\e[4m" "$*"; }
red_bold() { print_in_color "\e[1;31m" "$*"; }
green_bold() { print_in_color "\e[1;32m" "$*"; }
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
blue_bold() { print_in_color "\e[1;34m" "$*"; }
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
red_underlined() { print_in_color "\e[4;31m" "$*"; }
green_underlined() { print_in_color "\e[4;32m" "$*"; }
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }

View file

@ -0,0 +1,57 @@
#!/usr/bin/env bash
_systemctl () {
systemctl --user "${@:2}" "autostart@$1.service"
}
_query_autostart_toml() {
tomlq -r --arg host "$HOSTNAME" \
'.hosts[$host].groups as $groups | .apps | to_entries[] | select(
(.value.hosts | contains([$host])) or
([.value.group] | inside($groups))
) | '"$1" \
"$XDG_CONFIG_HOME/autostart.toml"
}
_list () {
_query_autostart_toml '.value.alias // .key'
}
_autostart_run_graphical () {
pass x # Try to unlock yubikey asap
start-audio pipewire
wait-for-service "network-online.target"
# Execute only if not already running
# Don't match keepassxc-proxy
if ! (pgrep -l keepassxc | grep -v prox) >/dev/null
then
if pass x
then
(pass keepass | head -n 1 | keepassxc --pw-stdin ~/sync/passwords.kdbx) &
fi
fi
autoinstall graphical
autostart-manage run
}
_echo_table () {
for unit in "$@"
do
printf "%s\t%s\t%s\t%s\n" \
"$unit" \
"$(_systemctl "$unit" is-enabled)" \
"$(_systemctl "$unit" is-active)" \
"$(_get_autostart_cmd "$unit")"
done
}
_get_autostart_cmd () {
_query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.command'
}
_get_autostart_delay () {
_query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.delay // 0'
}

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
_list

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
journalctl --user -fu "autostart@${args[program]:?}.service"

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
systemctl --user start autostart.target

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
_autostart_run_graphical
killall -SIGUSR2 waybar

View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
feh --bg-fill "$XDG_PICTURES_DIR/wallpaper/active_wallpaper"
"$HOME/.config/polybar/launch.sh" &
"$HOME/.config/bspwm/focus-voip.py" &
numlockx on
xsetroot -cursor_name left_ptr
xrdb "$HOME/.Xresources"
_autostart_run_graphical

View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
rm "$HOME/.config/systemd/user/autostart.target.wants/"*
autostart_units=()
while IFS='' read -r line
do
autostart_units+=("$line")
done < <(_list)
for unit in "${autostart_units[@]}"
do
_systemctl "$unit" add-wants autostart.target
done

View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
systemctl_args=("$action")
if [[ $action == "enable" ]]; then
systemctl_args=("add-wants" "autostart.target")
fi
#shellcheck disable=SC2068
_systemctl "${args[program]:?}" "${systemctl_args[@]}"

49
settings.yml Normal file
View file

@ -0,0 +1,49 @@
# The path to bashly.yml
config_path: "%{source_dir}/bashly.yml"
# The path to use for creating the bash script
target_dir: output
# The path to use for common library files, relative to source_dir
lib_dir: lib
# The path to use for command files, relative to source_dir
# When set to nil (~), command files will be placed directly under source_dir
# When set to any other string, command files will be placed under this
# directory, and each command will get its own subdirectory
commands_dir: ~
# Configure the bash options that will be added to the initialize function:
# strict: true Bash strict mode (set -euo pipefail)
# strict: false Only exit on errors (set -e)
# strict: '' Do not add any 'set' directive
# strict: <string> Add any other custom 'set' directive
strict: true
# When true, the generated script will use tab indentation instead of spaces
# (every 2 leading spaces will be converted to a tab character)
tab_indent: true
# When true, the generated script will consider any argument in the form of
# `-abc` as if it is `-a -b -c`.
compact_short_flags: true
# Set to 'production' or 'development':
# env: production Generate a smaller script, without file markers
# env: development Generate with file markers
env: development
# The extension to use when reading/writing partial script snippets
partials_extension: sh
# Display various usage elements in color by providing the name of the color
# function. The value for each property is a name of a function that is
# available in your script, for example: `green` or `bold`.
# You can run `bashly add colors` to add a standard colors library.
# This option cannot be set via environment variables.
usage_colors:
caption: blue
command: green
arg: red
flag: yellow
environment_variable: cyan

6
shell.nix Normal file
View file

@ -0,0 +1,6 @@
with import <nixpkgs> {};
mkShell {
nativeBuildInputs = [
bashly
];
}