aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: 60a09579250f8f2a5eab86dbd4b8fff958f19cf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
# Build and install for the current user. Use --debug for a faster development build.
profile=release
if [[ ${1:-} == --debug ]]; then profile=debug; fi
build_args=(--locked)
if [[ $profile == release ]]; then build_args+=(--release); fi
cargo build "${build_args[@]}" -j "${CARGO_BUILD_JOBS:-4}"
bin_dir="$HOME/.local/bin"
data_dir="${XDG_DATA_HOME:-$HOME/.local/share}"
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/ducky"
install -d "$bin_dir" "$data_dir/applications" "$data_dir/icons/hicolor/scalable/apps" "$config_dir"
install -m 755 "target/$profile/ducky" "$bin_dir/ducky"
install -d "$config_dir/themes"
if [[ ! -e $config_dir/shell.bash ]]; then install -m 644 assets/shell.bash "$config_dir/shell.bash"; fi
if [[ ! -e $config_dir/themes/lagoon.lua ]]; then install -m 644 assets/themes/lagoon.lua "$config_dir/themes/lagoon.lua"; fi
install -m 644 assets/ducky.svg "$data_dir/icons/hicolor/scalable/apps/dev.ducky.shell.svg"
if [[ ! -e $config_dir/config.lua ]]; then install -m 644 assets/config.lua "$config_dir/config.lua"; fi
# Desktop Exec fields have their own quoting rules (not shell quoting).
python3 - "$bin_dir/ducky" "$data_dir/applications/dev.ducky.shell.desktop" <<'PY'
import sys
exe = sys.argv[1].replace('\\', '\\\\').replace('"', '\\"').replace('`', '\\`').replace('$', '\\$').replace('%', '%%')
with open(sys.argv[2], 'w') as f:
    f.write('[Desktop Entry]\nType=Application\nName=Ducky Shell\nComment=Customizable native shell\n'
            f'Exec="{exe}"\nIcon=dev.ducky.shell\nTerminal=false\nCategories=System;TerminalEmulator;\n'
            'Keywords=terminal;shell;lua;\nStartupNotify=true\nStartupWMClass=dev.ducky.shell\n')
PY
# Make the user-local executable directory persistent in common login shells.
path_line='export PATH="$HOME/.local/bin:$PATH"'
for rc in "$HOME/.profile" "$HOME/.bashrc"; do
    if ! grep -Fq '# Ducky user-local binaries' "$rc" 2>/dev/null; then
        printf '\n# Ducky user-local binaries\n%s\n' "$path_line" >> "$rc"
    fi
done
if [[ -f $HOME/.zshrc || ${SHELL:-} == */zsh ]]; then
    if ! grep -Fq '# Ducky user-local binaries' "$HOME/.zshrc" 2>/dev/null; then
        printf '\n# Ducky user-local binaries\n%s\n' "$path_line" >> "$HOME/.zshrc"
    fi
fi
if [[ -d $HOME/.config/fish || ${SHELL:-} == */fish ]]; then
    install -d "$HOME/.config/fish/conf.d"
    printf 'fish_add_path "$HOME/.local/bin"\n' > "$HOME/.config/fish/conf.d/ducky-path.fish"
fi
command -v update-desktop-database >/dev/null && update-desktop-database "$data_dir/applications" || true
command -v gtk-update-icon-cache >/dev/null && gtk-update-icon-cache -f -t "$data_dir/icons/hicolor" >/dev/null 2>&1 || true
printf '\nInstalled %s/ducky and Ducky Shell in your app launcher.\n' "$bin_dir"
printf 'Config: %s/config.lua\nOpen a new terminal or run: export PATH="$HOME/.local/bin:$PATH"\n' "$config_dir"