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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/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.
platform=$(uname -s)
case "$platform" in
Linux) default_config="$HOME/.config" ;;
Darwin) default_config="$HOME/Library/Application Support" ;;
*) printf 'Unsupported platform: %s\n' "$platform" >&2; exit 1 ;;
esac
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:-$default_config}/ducky"
install -d "$bin_dir" "$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
if [[ $platform == Linux ]]; then
install -d "$data_dir/applications" "$data_dir/icons/hicolor/scalable/apps"
install -m 644 assets/ducky.svg "$data_dir/icons/hicolor/scalable/apps/dev.ducky.shell.svg"
# 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
else
app_dir="$HOME/Applications/Ducky.app"
install -d "$app_dir/Contents/MacOS"
install -m 755 "target/$profile/ducky" "$app_dir/Contents/MacOS/ducky"
python3 - "$app_dir/Contents/Info.plist" <<'PYINFO'
import plistlib, sys
with open(sys.argv[1], 'wb') as f:
plistlib.dump({
'CFBundleName': 'Ducky',
'CFBundleDisplayName': 'Ducky',
'CFBundleIdentifier': 'dev.ducky.shell',
'CFBundleExecutable': 'ducky',
'CFBundlePackageType': 'APPL',
'CFBundleShortVersionString': '0.1.0',
'CFBundleVersion': '1',
'NSHighResolutionCapable': True,
}, f)
PYINFO
# Sign locally built code for the current Mac; no developer certificate required.
codesign --force --deep --sign - "$app_dir"
register=/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
if [[ -x $register ]]; then "$register" -f "$app_dir"; fi
printf 'Installed %s (open with Finder or Spotlight).\n' "$app_dir"
fi
if [[ ! -e $config_dir/config.lua ]]; then install -m 644 assets/config.lua "$config_dir/config.lua"; fi
# 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" "$HOME/.bash_profile"; 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
if [[ $platform == Linux ]]; then
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"
fi
printf 'Config: %s/config.lua\nOpen a new terminal or run: export PATH="$HOME/.local/bin:$PATH"\n' "$config_dir"
|