mirror of
https://github.com/fscotto/infra.git
synced 2026-05-31 07:49:57 +00:00
Restrict tmux and desktop tools to Void hosts
This commit is contained in:
139
dotfiles/desktop/.tmux/plugins/tmux-autoreload/.gitignore
vendored
Normal file
139
dotfiles/desktop/.tmux/plugins/tmux-autoreload/.gitignore
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,vim,git,zsh
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,vim,git,zsh
|
||||
|
||||
### Git ###
|
||||
# Created by git for backups. To disable backups in Git:
|
||||
# $ git config --global mergetool.keepBackup false
|
||||
*.orig
|
||||
|
||||
# Created by git when using merge tools for conflicts
|
||||
*.BACKUP.*
|
||||
*.BASE.*
|
||||
*.LOCAL.*
|
||||
*.REMOTE.*
|
||||
*_BACKUP_*.txt
|
||||
*_BASE_*.txt
|
||||
*_LOCAL_*.txt
|
||||
*_REMOTE_*.txt
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Vim ###
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
Sessionx.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
### Zsh ###
|
||||
# Zsh compiled script + zrecompile backup
|
||||
*.zwc
|
||||
*.zwc.old
|
||||
|
||||
# Zsh completion-optimization dumpfile
|
||||
*zcompdump*
|
||||
|
||||
# Zsh zcalc history
|
||||
.zcalc_history
|
||||
|
||||
# A popular plugin manager's files
|
||||
._zinit
|
||||
.zinit_lstupd
|
||||
|
||||
# zdharma/zshelldoc tool's files
|
||||
zsdoc/data
|
||||
|
||||
# robbyrussell/oh-my-zsh/plugins/per-directory-history plugin's files
|
||||
# (when set-up to store the history in the local directory)
|
||||
.directory_history
|
||||
|
||||
# MichaelAquilina/zsh-autoswitch-virtualenv plugin's files
|
||||
# (for Zsh plugins using Python)
|
||||
.venv
|
||||
|
||||
# Zunit tests' output
|
||||
/tests/_output/*
|
||||
!/tests/_output/.gitkeep
|
||||
|
||||
21
dotfiles/desktop/.tmux/plugins/tmux-autoreload/LICENSE
Normal file
21
dotfiles/desktop/.tmux/plugins/tmux-autoreload/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Maddison Hellstrom
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
166
dotfiles/desktop/.tmux/plugins/tmux-autoreload/README.md
Normal file
166
dotfiles/desktop/.tmux/plugins/tmux-autoreload/README.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# tmux-autoreload [](https://github.com/b0o/tmux-autoreload/releases) [](https://mit-license.org)
|
||||
|
||||
tmux-autoreload watches your tmux configuration file and automatically reloads
|
||||
it on change.
|
||||
|
||||
## Install
|
||||
|
||||
#### Dependencies
|
||||
|
||||
- [entr](https://github.com/eradman/entr)
|
||||
|
||||
## Installation
|
||||
|
||||
To install tmux-autoreload with TPM (https://github.com/tmux-plugins/tpm), add the
|
||||
following line to the end of your tmux configuration file:
|
||||
|
||||
```sh
|
||||
set-option -g @plugin 'b0o/tmux-autoreload'
|
||||
```
|
||||
|
||||
Then, inside tmux, press `prefix + I` to fetch the plugin.
|
||||
|
||||
If you don't use a plugin manager, git clone tmux-autoreload to the location of your
|
||||
choice and run it directly:
|
||||
|
||||
```sh
|
||||
run-shell "/path/to/tmux-autoreload/tmux-autoreload.tmux"
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
Once installed, you should be good to go unless you use non-standard
|
||||
configuration file paths or want to customize how tmux-autoreload behaves.
|
||||
|
||||
### Configuration file paths
|
||||
|
||||
If your tmux config file is at a non-standard location or if you have multiple,
|
||||
specify them in `@tmux-autoreload-configs`, separated by commas:
|
||||
|
||||
```sh
|
||||
set-option -g @tmux-autoreload-configs '/path/to/configs/a.conf,/path/to/configs/b.conf'
|
||||
```
|
||||
|
||||
### Entrypoints
|
||||
|
||||
Normally, tmux-autoreload will source whichever file changed. If you wish to
|
||||
source a specific set of files when any configuration file changes, use
|
||||
`@tmux-autoreload-entrypoints`:
|
||||
|
||||
```sh
|
||||
set-option -g @tmux-autoreload-entrypoints '/path/to/entrypoint.conf'
|
||||
```
|
||||
|
||||
You can specify multiple entrypoints separated by commas. All entrypoints
|
||||
will be sourced when any watched file changes.
|
||||
|
||||
Set `@tmux-autoreload-entrypoints` to 1 to use the standard tmux configuration
|
||||
files as entrypoints, usually `/etc/tmux.conf` and `~/.tmux.conf.` You can see
|
||||
these files with:
|
||||
|
||||
```sh
|
||||
tmux display-message -p "#{config_files}"
|
||||
```
|
||||
|
||||
#### Entrypoint Notes
|
||||
|
||||
- If entrypoints are configured, a changed file itself will not necessarily
|
||||
be reloaded unless it's an entrypoint or is sourced by an entrypoint.
|
||||
|
||||
- Entrypoints will not be watched unless they're a standard tmux
|
||||
configuration file like `~/.tmux.conf` or are included in `@tmux-autoreload-configs.`
|
||||
|
||||
### All Options
|
||||
|
||||
```
|
||||
@tmux-autoreload-configs (Default: unset)
|
||||
A comma-delimited list of paths to configuration files which should be
|
||||
watched in addition to the base tmux configuration files.
|
||||
|
||||
@tmux-autoreload-entrypoints (Default: unset)
|
||||
A comma-delimited list of paths to configuration files which should be
|
||||
reloaded when any watched configuration file changes. If unset, the changed
|
||||
file itself will be reloaded.
|
||||
|
||||
If set, only the entrypoints will be reloaded, not necessarily the changed
|
||||
file.
|
||||
|
||||
If set to 1, the base tmux configuration files are used as the entrypoints
|
||||
(you can see the base configuration files with the command tmux
|
||||
display-message -p "#{config_files}").
|
||||
|
||||
@tmux-autoreload-quiet 0|1 (Default: 0)
|
||||
If set to 1, tmux-autoreload will not display status messages.
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
<!-- USAGE -->
|
||||
|
||||
```
|
||||
|
||||
Usage: tmux-autoreload.tmux [-f] [OPT...]
|
||||
Automatically reloads your tmux configuration files on change.
|
||||
|
||||
Options
|
||||
-h Display usage information.
|
||||
-v Display tmux-autoreload version and copyright information.
|
||||
-f Run in foreground (do not fork).
|
||||
-k Kill the running tmux-autoreload instance.
|
||||
-s Show tmux-autoreload status
|
||||
|
||||
Installation
|
||||
To install tmux-autoreload with TPM (https://github.com/tmux-plugins/tpm), add the
|
||||
following line to the end of your tmux configuration file:
|
||||
set-option -g @plugin 'b0o/tmux-autoreload'
|
||||
|
||||
If you don't use a plugin manager, git clone tmux-autoreload to the location of your
|
||||
choice and run it directly:
|
||||
run-shell "/path/to/tmux-autoreload/tmux-autoreload.tmux"
|
||||
|
||||
Once installed, you should be good to go unless you use non-standard
|
||||
configuration file paths or want to customize how tmux-autoreload behaves.
|
||||
|
||||
Configuration file paths
|
||||
If your config file is at a non-standard location or if you have multiple,
|
||||
specify them in @tmux-autoreload-configs, separated by commas:
|
||||
set-option -g @tmux-autoreload-configs '/path/to/configs/a.conf,/path/to/configs/b.conf'
|
||||
|
||||
Entrypoints
|
||||
Normally, tmux-autoreload will source whichever file changed. If you wish to
|
||||
source a specific set of files when any configuration file changes, use
|
||||
@tmux-autoreload-entrypoints:
|
||||
set-option -g @tmux-autoreload-entrypoints '/path/to/entrypoint.conf'
|
||||
|
||||
You can specify multiple entrypoints separated by commas. All entrypoints
|
||||
will be sourced when any watched file changes.
|
||||
|
||||
Set @tmux-autoreload-entrypoints to 1 to use the standard tmux configuration
|
||||
files as entrypoints, usually /etc/tmux.conf and ~/.tmux.conf. You can see
|
||||
these files with:
|
||||
tmux display-message -p "#{config_files}".
|
||||
|
||||
Entrypoint Notes:
|
||||
- If entrypoints are configured, a changed file itself will not necessarily
|
||||
be reloaded unless it's an entrypoint or is sourced by an entrypoint.
|
||||
|
||||
- Entrypoints will not be watched unless they're a standard tmux
|
||||
configuration file like ~/.tmux.conf or are included in @tmux-autoreload-configs.
|
||||
|
||||
Other Options
|
||||
@tmux-autoreload-quiet 0|1 (Default: 0)
|
||||
If set to 1, tmux-autoreload will not display messages
|
||||
|
||||
```
|
||||
|
||||
<!-- /USAGE -->
|
||||
|
||||
## License
|
||||
|
||||
<!-- LICENSE -->
|
||||
|
||||
© 2021 Maddison Hellstrom
|
||||
|
||||
Released under the MIT License.
|
||||
|
||||
<!-- /LICENSE -->
|
||||
154
dotfiles/desktop/.tmux/plugins/tmux-autoreload/scripts/gendocs.sh
Executable file
154
dotfiles/desktop/.tmux/plugins/tmux-autoreload/scripts/gendocs.sh
Executable file
@@ -0,0 +1,154 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (C) 2020-2021 Maddison Hellstrom <https://github.com/b0o>, MIT License.
|
||||
|
||||
set -Eeuo pipefail
|
||||
if [[ ${BASH_VERSINFO[0]} -ge 5 || (${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -ge 4) ]]; then
|
||||
shopt -s inherit_errexit
|
||||
fi
|
||||
|
||||
declare -g self prog basedir reporoot
|
||||
self="$(readlink -e "${BASH_SOURCE[0]}")"
|
||||
prog="$(basename "$self")"
|
||||
basedir="$(realpath -m "$self/..")"
|
||||
reporoot="$(realpath -m "$basedir/..")"
|
||||
|
||||
# gendocs configuration {{{
|
||||
|
||||
declare -g main="${reporoot}/tmux-autoreload.tmux"
|
||||
|
||||
declare -gA targets=(
|
||||
[readme]="$reporoot/README.md"
|
||||
)
|
||||
|
||||
declare -gi copyright_start=2021
|
||||
|
||||
function target_readme() {
|
||||
section -s USAGE -c <<< "$("$main" -h 2>&1)"
|
||||
section -s LICENSE << EOF
|
||||
© ${copyright_start}$( (($(date +%Y) == copyright_start)) || date +-%Y) Maddison Hellstrom
|
||||
|
||||
Released under the MIT License.
|
||||
EOF
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
||||
declare -gA sections
|
||||
|
||||
function section() {
|
||||
local section
|
||||
local -i code=0
|
||||
local lang
|
||||
|
||||
local opt OPTARG
|
||||
local -i OPTIND
|
||||
while getopts "s:cC:" opt "$@"; do
|
||||
case "$opt" in
|
||||
s)
|
||||
section="$OPTARG"
|
||||
;;
|
||||
c)
|
||||
code=1
|
||||
;;
|
||||
C)
|
||||
code=1
|
||||
lang="$OPTARG"
|
||||
;;
|
||||
\?)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
local -a lines=('')
|
||||
|
||||
if [[ $code -eq 1 ]]; then
|
||||
lines+=('```'"${lang:-}" '')
|
||||
fi
|
||||
|
||||
mapfile -tO ${#lines[@]} lines
|
||||
|
||||
if [[ $code -eq 1 ]]; then
|
||||
lines+=('' '```')
|
||||
fi
|
||||
|
||||
sections["$section"]="$(printf '%s\n' "${lines[@]}")\n"
|
||||
}
|
||||
|
||||
function regen_section() {
|
||||
local section="$1"
|
||||
local content="${sections[$section]}"
|
||||
awk < "$target" -v "section=$section" -v "content=$content" '
|
||||
BEGIN {
|
||||
d = 0
|
||||
}
|
||||
|
||||
{
|
||||
if (match($0, "^<!-- " section " -->$")) {
|
||||
d = 1
|
||||
print $0
|
||||
print content
|
||||
next
|
||||
}
|
||||
if (match($0, "^<!-- /" section " -->$")) {
|
||||
d = 0
|
||||
print $0
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
d == 0 {
|
||||
print $0
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
function main() {
|
||||
local opt OPTARG
|
||||
local -i OPTIND
|
||||
while getopts "h" opt "$@"; do
|
||||
case "$opt" in
|
||||
h)
|
||||
echo "usage: $prog [opt].. [target].." >&2
|
||||
return 0
|
||||
;;
|
||||
\?)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
local -a targets_selected=("${!targets[@]}")
|
||||
|
||||
if [[ $# -gt 0 ]]; then
|
||||
targets_selected=("$@")
|
||||
fi
|
||||
|
||||
local t target
|
||||
for t in "${targets_selected[@]}"; do
|
||||
[[ -v "targets[$t]" ]] || {
|
||||
echo "unknown target: $t" >&2
|
||||
return 1
|
||||
}
|
||||
target="${targets["$t"]}"
|
||||
[[ -e "$target" ]] || {
|
||||
echo "target file not found: $target" >&2
|
||||
return 1
|
||||
}
|
||||
sections=()
|
||||
"target_${t}" || {
|
||||
echo "unknown target: $t"
|
||||
return 1
|
||||
}
|
||||
local s
|
||||
for s in "${!sections[@]}"; do
|
||||
regen_section "$s" > "${target}_"
|
||||
mv "${target}_" "$target"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
main "$@"
|
||||
258
dotfiles/desktop/.tmux/plugins/tmux-autoreload/tmux-autoreload.tmux
Executable file
258
dotfiles/desktop/.tmux/plugins/tmux-autoreload/tmux-autoreload.tmux
Executable file
@@ -0,0 +1,258 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Automatically reloads your tmux configuration files on change.
|
||||
#
|
||||
# Copyright 2021 Maddison Hellstrom <github.com/b0o>, MIT License.
|
||||
|
||||
set -Eeuo pipefail
|
||||
if [[ ${BASH_VERSINFO[0]} -ge 5 || (${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -ge 4) ]]; then
|
||||
shopt -s inherit_errexit
|
||||
fi
|
||||
|
||||
function years_from() {
|
||||
local from="$1" to
|
||||
to="${2:-$(date +%Y)}"
|
||||
if [[ "$from" == "$to" ]]; then
|
||||
echo "$from"
|
||||
else
|
||||
echo "$from-$to"
|
||||
fi
|
||||
}
|
||||
|
||||
declare -g self prog name
|
||||
self="$(realpath -e "${BASH_SOURCE[0]}")"
|
||||
prog="$(basename "$self")"
|
||||
name="${prog%.tmux}"
|
||||
|
||||
declare -gr version="0.0.1"
|
||||
declare -gr authors=("$(years_from 2021) Maddison Hellstrom <github.com/b0o>")
|
||||
declare -gr repo_short="b0o/$name"
|
||||
declare -gr repository="https://github.com/$repo_short"
|
||||
declare -gr issues="https://github.com/$repo_short/issues"
|
||||
declare -gr license="MIT"
|
||||
declare -gr license_url="https://mit-license.org"
|
||||
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
Usage: $prog [-f] [OPT...]
|
||||
Automatically reloads your tmux configuration files on change.
|
||||
|
||||
Options
|
||||
-h Display usage information.
|
||||
-v Display $name version and copyright information.
|
||||
-f Run in foreground (do not fork).
|
||||
-k Kill the running $name instance.
|
||||
-s Show $name status
|
||||
|
||||
Installation
|
||||
To install $name with TPM (https://github.com/tmux-plugins/tpm), add the
|
||||
following line to the end of your tmux configuration file:
|
||||
set-option -g @plugin '$repo_short'
|
||||
|
||||
If you don't use a plugin manager, git clone $name to the location of your
|
||||
choice and run it directly:
|
||||
run-shell "/path/to/$name/$prog"
|
||||
|
||||
Once installed, you should be good to go unless you use non-standard
|
||||
configuration file paths or want to customize how $name behaves.
|
||||
|
||||
Configuration file paths
|
||||
If your config file is at a non-standard location or if you have multiple,
|
||||
specify them in @$name-configs, separated by commas:
|
||||
set-option -g @$name-configs '/path/to/configs/a.conf,/path/to/configs/b.conf'
|
||||
|
||||
Entrypoints
|
||||
Normally, $name will source whichever file changed. If you wish to
|
||||
source a specific set of files when any configuration file changes, use
|
||||
@$name-entrypoints:
|
||||
set-option -g @$name-entrypoints '/path/to/entrypoint.conf'
|
||||
|
||||
You can specify multiple entrypoints separated by commas. All entrypoints
|
||||
will be sourced when any watched file changes.
|
||||
|
||||
Set @$name-entrypoints to 1 to use the standard tmux configuration
|
||||
files as entrypoints, usually /etc/tmux.conf and ~/.tmux.conf. You can see
|
||||
these files with:
|
||||
tmux display-message -p "#{config_files}".
|
||||
|
||||
Entrypoint Notes:
|
||||
- If entrypoints are configured, a changed file itself will not necessarily
|
||||
be reloaded unless it's an entrypoint or is sourced by an entrypoint.
|
||||
|
||||
- Entrypoints will not be watched unless they're a standard tmux
|
||||
configuration file like ~/.tmux.conf or are included in @$name-configs.
|
||||
|
||||
Other Options
|
||||
@$name-quiet 0|1 (Default: 0)
|
||||
If set to 1, $name will not display messages
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
function usage_version() {
|
||||
cat <<EOF
|
||||
$name v$version
|
||||
|
||||
Repository: $repository
|
||||
Issues: $issues
|
||||
License: $license ($license_url)
|
||||
Copyright: ${authors[0]}
|
||||
EOF
|
||||
if [[ ${#authors[@]} -gt 1 ]]; then
|
||||
printf ' %s\n' "${authors[@]:1}"
|
||||
fi
|
||||
}
|
||||
|
||||
function display_message() {
|
||||
if [[ "$(tmux show-option -gv "@$name-quiet")" == "1" ]]; then
|
||||
return 0
|
||||
fi
|
||||
# `tmux display-message -c` is broken in v3.2a
|
||||
# https://github.com/tmux/tmux/issues/2737#issuecomment-898861216
|
||||
if [[ "$(tmux display-message -p "#{version}")" == "3.2a" ]]; then
|
||||
tmux display-message "$@"
|
||||
else
|
||||
while read -r client; do
|
||||
tmux display-message -c "$client" "$@"
|
||||
done < <(tmux list-clients -F '#{client_name}')
|
||||
fi
|
||||
}
|
||||
|
||||
function get_base_configs() {
|
||||
tmux display-message -p "#{config_files}" | tr ',' '\n' | sort -u
|
||||
}
|
||||
|
||||
function get_user_configs() {
|
||||
tmux show-option -gv "@$name-configs" | tr ',' '\n' | sort -u
|
||||
}
|
||||
|
||||
function get_entrypoints() {
|
||||
local entrypoints
|
||||
entrypoints="$(tmux show-option -gv "@$name-entrypoints")"
|
||||
if [[ -z "$entrypoints" || "$entrypoints" == "0" ]]; then
|
||||
return 0
|
||||
fi
|
||||
if [[ "$entrypoints" == "1" ]]; then
|
||||
get_base_configs
|
||||
else
|
||||
echo "$entrypoints" | tr ',' '\n'
|
||||
fi
|
||||
}
|
||||
|
||||
function get_instance() {
|
||||
local -i instance_pid
|
||||
instance_pid="$(tmux show-options -gv "@$name-pid")"
|
||||
if [[ "$instance_pid" -gt 0 ]] && ps "$instance_pid" &>/dev/null; then
|
||||
echo "$instance_pid"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function reload() {
|
||||
local -a entrypoints
|
||||
mapfile -t entrypoints < <(get_entrypoints)
|
||||
if [[ ${#entrypoints[@]} -eq 0 ]]; then
|
||||
entrypoints=("$@")
|
||||
fi
|
||||
if msg="$(tmux source-file "${entrypoints[@]}")"; then
|
||||
display_message "Reloaded $(
|
||||
printf '%s\n' "${entrypoints[@]}" | xargs -n1 basename | tr '\n' ',' | sed 's/,$/\n/; s/,/, /g'
|
||||
)"
|
||||
else
|
||||
display_message -d 0 "#[fg=white,bg=red,bold]ERROR: $msg"
|
||||
fi
|
||||
}
|
||||
|
||||
function onexit() {
|
||||
local -i code=$?
|
||||
local -i entr_pid=$1
|
||||
display_message "$name exited with code $code" || true
|
||||
if [[ -v entr_pid && $entr_pid -gt 1 ]] && ps "$entr_pid" &>/dev/null; then
|
||||
kill "$entr_pid" || true
|
||||
fi
|
||||
tmux set-option -gu "@$name-pid" &
|
||||
return "$code"
|
||||
}
|
||||
|
||||
function kill_instance() {
|
||||
local -i instance_pid
|
||||
if instance_pid="$(get_instance)"; then
|
||||
kill "$instance_pid"
|
||||
return $?
|
||||
fi
|
||||
echo "$name -k: kill failed: no instance found" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
function get_status() {
|
||||
local -i instance_pid
|
||||
if instance_pid="$(get_instance)"; then
|
||||
echo "running: $instance_pid"
|
||||
return 0
|
||||
fi
|
||||
echo "not running"
|
||||
return 1
|
||||
}
|
||||
|
||||
function main() {
|
||||
if ! [[ "${1:-}" =~ ^-[hvfksr]$ ]]; then
|
||||
"$self" -f "$@" &>/dev/null &
|
||||
disown
|
||||
exit $?
|
||||
fi
|
||||
|
||||
local opt OPTARG
|
||||
local -i OPTIND
|
||||
while getopts "hvfksr:" opt "$@"; do
|
||||
case "$opt" in
|
||||
h)
|
||||
usage
|
||||
return 0
|
||||
;;
|
||||
v)
|
||||
usage_version
|
||||
return 0
|
||||
;;
|
||||
f)
|
||||
# Silently ignore -f
|
||||
;;
|
||||
k)
|
||||
kill_instance
|
||||
return
|
||||
;;
|
||||
s)
|
||||
get_status
|
||||
return
|
||||
;;
|
||||
r)
|
||||
reload "$OPTARG"
|
||||
return
|
||||
;;
|
||||
\?)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if get_instance &>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
command -v entr &>/dev/null || {
|
||||
echo "Command not found: entr" >&2
|
||||
display_message -d 0 "Failed to start $name: Command not found: entr"
|
||||
return 1
|
||||
}
|
||||
|
||||
tmux set-option -g "@$name-pid" $$
|
||||
|
||||
# shellcheck disable=2016
|
||||
entr -np sh -c '"$0" -r "$1"' "$self" /_ <<<"$(printf '%s\n' "$(get_base_configs)" "$(get_user_configs)")" &
|
||||
# shellcheck disable=2064
|
||||
trap "onexit $!" EXIT
|
||||
wait
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user