nix/home/program/bash/module/Bottle.nix
2024-12-12 05:27:20 +03:00

77 lines
1.6 KiB
Nix

{ ... }: {
text = ''
# Switch bottle.
# Usage: bt <NAME>
function bt() {
export SHELL_NAME="''${*}"
}
# Create new bottle.
# Usage: btc [ENV] [EXTRA]
function btc() {
local env="''${1}"
[[ "''${env}" = "" ]] && env="gaming"
bottles-cli new --bottle-name "''${SHELL_NAME}" --environment "''${env}" "''${@:2}"
}
# Run an exe inside a bottle.
# Usage: bte <EXE> [EXTRA]
function bte() {
bottles-cli run -b "''${SHELL_NAME}" -e "''${@}"
}
# Run a program inside a bottle.
# Usage: btr <NAME> [EXTRA]
function btr() {
bottles-cli run -b "''${SHELL_NAME}" -p "''${@}"
}
# List bottles.
function btl() {
bottles-cli list bottles
}
# List programs in a bottle.
function btlp() {
bottles-cli programs -b "''${SHELL_NAME}"
}
# Add a program to bottle.
# Usage: bta <NAME> <EXE> [EXTRA]
function bta() {
local name="''${1}"
local exe=$(printf "%q" "''${2}")
if [[ "''${exe}" = "" ]]; then
help bta
return 2
fi
bottles-cli add -b "''${SHELL_NAME}" -n "''${name}" -p "$(realpath ''${exe})" "''${@:3}"
}
# Set bottle env var.
# Usage: bte <NAME=VALUE>
function bte() {
local env="''${1}"
if [[ "''${env}" = "" ]]; then
help bte
return 2
fi
bottles-cli edit -b "''${SHELL_NAME}" --env-var "''${@}"
}
function _comp_bottles_list() {
_autocomplete $(bottles-cli list bottles 2> /dev/null | sed -e "1d; s/^- //")
}
function _comp_programs_list() {
local IFS=$'\n'
_autocomplete $(bottles-cli programs -b "''${SHELL_NAME}" 2> /dev/null | sed -e "1d; s/^- //")
}
complete -F _comp_bottles_list bt
complete -F _comp_programs_list btr
'';
}