Bottles: Add cli.
This commit is contained in:
parent
a8198e354f
commit
7b23da80d2
|
@ -20,6 +20,7 @@ in {
|
|||
+ mkHost "fmpmaven" "10.30.22.10" 22 "root"
|
||||
+ mkHost "home" "10.0.0.1" 22143 "root"
|
||||
+ mkHost "laptop" "192.168.1.9" 22143 "root"
|
||||
+ mkHost "max" "10.0.0.13" 22143 "root"
|
||||
+ mkHost "nixbuilder" "10.0.0.1" 22143 "nixbuilder"
|
||||
+ mkHost "pi" "192.168.1.6" 22143 "root"
|
||||
+ mkHost "pocket" "192.168.1.11" 22143 "root"
|
||||
|
|
|
@ -357,7 +357,7 @@
|
|||
|
||||
# Autocomplete with names of all archives.
|
||||
function _comp_archive_names() {
|
||||
_autocomplete_first $(_archive_names)
|
||||
_autocomplete $(_archive_names)
|
||||
}
|
||||
|
||||
# Check if file is an archive.
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
function _complete_ask_model() {
|
||||
local IFS=$'\n'
|
||||
local models=($(ollama list | sed -e "1d" | cut -f1))
|
||||
_autocomplete_first ''${models[@]}
|
||||
_autocomplete ''${models[@]}
|
||||
}
|
||||
|
||||
complete -F _complete_ask_model ask_model
|
||||
|
|
|
@ -4,54 +4,14 @@
|
|||
# There are also options like -o nospace. see man for more info.
|
||||
# Usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo
|
||||
function _autocomplete() {
|
||||
local IFS=$'\n'
|
||||
local commands="''${*}"
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
local cur="''${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="''${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local command="''${COMP_WORDS[0]}"
|
||||
|
||||
COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) )
|
||||
return 0
|
||||
}
|
||||
|
||||
# Autocomplete only first argument.
|
||||
function _autocomplete_first() {
|
||||
local IFS=$'\n'
|
||||
local commands="''${*}"
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
local cur="''${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="''${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local command="''${COMP_WORDS[0]}"
|
||||
|
||||
if [[ "''${prev}" = "''${command}" ]]; then
|
||||
COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) )
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Autocomplete only first argument and the rest with files.
|
||||
function _autocomplete_first_ls() {
|
||||
local IFS=$'\n'
|
||||
local commands="''${*}"
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
local cur="''${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="''${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local command="''${COMP_WORDS[0]}"
|
||||
|
||||
if [[ "''${prev}" = "''${command}" ]]; then
|
||||
COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) )
|
||||
return 0
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "$(ls)" -- ''${cur}) )
|
||||
return 0
|
||||
local iter use cur
|
||||
cur=''${COMP_WORDS[COMP_CWORD]}
|
||||
use="''${@//\\ /___}"
|
||||
for iter in $use; do
|
||||
if [[ $iter =~ ^$cur ]]; then
|
||||
COMPREPLY+=( $(printf "%q" "''${iter//___/ }") )
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Autocomplete by grepping file names.
|
||||
|
@ -60,12 +20,8 @@
|
|||
COMPREPLY=()
|
||||
|
||||
local pattern="''${1}"
|
||||
local cur="''${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="''${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local command="''${COMP_WORDS[0]}"
|
||||
|
||||
COMPREPLY=( $(compgen -W "$(ls | grep -E ''${pattern})" -- ''${cur}) )
|
||||
return 0
|
||||
local candidates=$("$(ls | grep -E ''${pattern})")
|
||||
_autocomplete ''${candidates}
|
||||
}
|
||||
|
||||
# Autocomplete nested program.
|
||||
|
|
76
home/program/bash/module/Bottle.nix
Normal file
76
home/program/bash/module/Bottle.nix
Normal file
|
@ -0,0 +1,76 @@
|
|||
{ ... }: {
|
||||
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 a file inside a bottle.
|
||||
# Usage: btre <EXE> [EXTRA]
|
||||
function btre() {
|
||||
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=$(realpath "''${2}")
|
||||
if [[ "''${exe}" = "" ]]; then
|
||||
help bta
|
||||
return 2
|
||||
fi
|
||||
|
||||
bottles-cli add -b "''${SHELL_NAME}" -n "''${name}" -p "''${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
|
||||
'';
|
||||
}
|
|
@ -65,7 +65,7 @@
|
|||
function _comp_cdd() {
|
||||
local IFS=$'\n'
|
||||
local dirs=($(_cdd_directories))
|
||||
_autocomplete_first ''${dirs[@]}
|
||||
_autocomplete ''${dirs[@]}
|
||||
}
|
||||
|
||||
complete -o nosort -o filenames -F _comp_cdd cdd
|
||||
|
|
|
@ -329,7 +329,7 @@
|
|||
|
||||
# Autocomplete with my git emails.
|
||||
function _gu() {
|
||||
_autocomplete_first hi@voronind.com dd.voronin@fsight.ru
|
||||
_autocomplete hi@voronind.com dd.voronin@fsight.ru
|
||||
}
|
||||
|
||||
complete -F _gu gu
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
# Autocomplete with available functions.
|
||||
function _help_functions() {
|
||||
_autocomplete_first $(find_function)
|
||||
_autocomplete $(find_function)
|
||||
}
|
||||
|
||||
complete -F _help_functions help h
|
||||
|
|
|
@ -391,7 +391,7 @@
|
|||
}
|
||||
|
||||
function _comp_name_parse() {
|
||||
_autocomplete_first_ls $(find_function | grep ^parse)
|
||||
_autocomplete $(find_function | grep ^parse)
|
||||
}
|
||||
|
||||
complete -o filenames -F _comp_name_parse name_parse
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
}
|
||||
|
||||
function _complete_own() {
|
||||
_autocomplete_first_ls $(_get_users)
|
||||
_autocomplete $(_get_users)
|
||||
}
|
||||
|
||||
complete -F _complete_own own
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
}
|
||||
|
||||
function _complete_s() {
|
||||
_autocomplete_first $(_get_users)
|
||||
_autocomplete $(_get_users)
|
||||
}
|
||||
|
||||
complete -F _complete_s s
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
|
||||
# Autocomplete with running sessions once.
|
||||
function _complete_tmux_session() {
|
||||
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
||||
_autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
||||
}
|
||||
|
||||
# Autocomplete with running sessions.
|
||||
|
@ -88,7 +88,7 @@
|
|||
|
||||
# Autocomplete with current dir name and dirs inside this one.
|
||||
function _complete_tmux_name() {
|
||||
_autocomplete_first "''${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//')
|
||||
_autocomplete "''${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//')
|
||||
}
|
||||
|
||||
complete -F _complete_tmux_session ta
|
||||
|
|
|
@ -131,6 +131,7 @@ in {
|
|||
(mkStatic "10.0.0.10" "9c:1c:37:62:3f:d5") # Printer.
|
||||
(mkStatic "10.0.0.11" "dc:a6:32:f5:77:95") # RPi.
|
||||
(mkStatic "10.0.0.12" "ec:9c:32:ad:bc:4a") # Camera.
|
||||
(mkStatic "10.0.0.13" "c0:a5:e8:b5:d9:16") # Max.
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue