#!/usr/bin/env bash set -euo pipefail project_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) data_home=${XDG_DATA_HOME:-"${HOME}/.local/share"} config_home=${XDG_CONFIG_HOME:-"${HOME}/.config"} binary_dir=${HOME}/.local/bin bar_config=${config_home}/lightbar/bar.conf cargo build --locked --release --manifest-path "${project_dir}/Cargo.toml" install -Dm755 "${project_dir}/target/release/lightbar" "${binary_dir}/lightbar" install -d "${config_home}/lightbar" if [[ ! -e "${config_home}/lightbar/config.toml" ]]; then install -m644 "${project_dir}/examples/config.toml" "${config_home}/lightbar/config.toml" fi if [[ ! -e "${config_home}/lightbar/theme.toml" ]]; then install -m644 "${project_dir}/examples/theme.toml" "${config_home}/lightbar/theme.toml" fi # Sway may be started with a PATH that does not contain ~/.local/bin. Keep the # path resolution out of the shared Sway config by generating this per-user # fragment with absolute paths at install time. bar_config_tmp=$(mktemp) trap 'rm -f "${bar_config_tmp}"' EXIT printf '%s\n' \ '# Generated by Lightbar. Re-run scripts/install.sh after moving the install.' \ 'bar lightbar {' \ " swaybar_command ${binary_dir}/lightbar --config ${config_home}/lightbar/config.toml" \ '}' > "${bar_config_tmp}" install -m644 "${bar_config_tmp}" "${bar_config}" rm -f "${bar_config_tmp}" trap - EXIT install -d "${data_home}/doc/lightbar" install -m644 "${project_dir}/README.md" "${data_home}/doc/lightbar/README.md" install -m644 "${project_dir}/TOOD.md" "${data_home}/doc/lightbar/TOOD.md" printf 'Installed %s\n' "${binary_dir}/lightbar" printf 'Configuration: %s\n' "${config_home}/lightbar/config.toml" printf 'Sway bar fragment: %s\n' "${bar_config}" printf 'Run: %s doctor\n' "${binary_dir}/lightbar" printf '\nAdd this at top level in your Sway config (and remove the old bar block):\n' if [[ "${config_home}" == "${HOME}/.config" ]]; then printf ' include ~/.config/lightbar/bar.conf\n' else printf ' include %s\n' "${bar_config}" fi