Compare commits
No commits in common. "main" and "v0.1.3" have entirely different histories.
17 changed files with 155 additions and 1490 deletions
|
|
@ -1,165 +0,0 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: rust:bookworm
|
||||
volumes:
|
||||
- /opt/runner/keys:/keys:ro
|
||||
|
||||
steps:
|
||||
- name: Install tools
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y dpkg-dev git curl openssh-client
|
||||
|
||||
- name: Setup SSH
|
||||
run: |
|
||||
test -r /keys/forgejo_runner || { echo "Deploy key /keys/forgejo_runner chybi"; exit 1; }
|
||||
install -m 600 /keys/forgejo_runner /tmp/forgejo_runner
|
||||
echo "GIT_SSH_COMMAND=ssh -p 554 -i /tmp/forgejo_runner -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Checkout source
|
||||
run: |
|
||||
git clone ssh://git@git-ssh.janvete.com:554/seth/lines.git src
|
||||
cd src
|
||||
git checkout "${{ github.ref_name }}"
|
||||
|
||||
- name: Build Linux release binary and .deb
|
||||
working-directory: src
|
||||
run: |
|
||||
VERSION=${{ github.ref_name }}
|
||||
VER=${VERSION#v}
|
||||
mkdir -p dist
|
||||
|
||||
cargo build --release
|
||||
|
||||
# .deb package
|
||||
DEB_DIR="lines_${VER}_amd64"
|
||||
mkdir -p "${DEB_DIR}/DEBIAN" "${DEB_DIR}/usr/bin"
|
||||
cp target/release/lines "${DEB_DIR}/usr/bin/lines"
|
||||
chmod 755 "${DEB_DIR}/usr/bin/lines"
|
||||
|
||||
cat > "${DEB_DIR}/DEBIAN/control" << CONTROL
|
||||
Package: lines
|
||||
Version: ${VER}
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: janvete <jan.vete@example.com>
|
||||
Description: TUI for running frequently used commands from markdown files
|
||||
CONTROL
|
||||
|
||||
dpkg-deb --build "${DEB_DIR}" "dist/${DEB_DIR}.deb"
|
||||
|
||||
# Linux tarball
|
||||
STAGING=$(mktemp -d)
|
||||
cp target/release/lines "${STAGING}/lines"
|
||||
tar -czf "dist/lines-${VERSION}-linux-amd64.tar.gz" -C "${STAGING}" lines
|
||||
rm -rf "${STAGING}"
|
||||
|
||||
- name: Print checksums
|
||||
working-directory: src
|
||||
run: |
|
||||
echo "=== SHA256 checksums ==="
|
||||
sha256sum dist/*
|
||||
|
||||
- name: Create Forgejo Release
|
||||
working-directory: src
|
||||
env:
|
||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
FORGEJO_URL: https://git.janvete.com
|
||||
run: |
|
||||
VERSION=${{ github.ref_name }}
|
||||
API="${FORGEJO_URL}/api/v1/repos/seth/lines"
|
||||
|
||||
RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \
|
||||
"${API}/releases")
|
||||
|
||||
echo "Create release response: ${RELEASE_JSON}"
|
||||
RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
|
||||
if [ -z "${RELEASE_ID}" ]; then
|
||||
echo "Release may already exist, fetching existing release..."
|
||||
EXISTING=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
"${API}/releases/tags/${VERSION}")
|
||||
echo "Existing release response: ${EXISTING}"
|
||||
RELEASE_ID=$(echo "${EXISTING}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
fi
|
||||
|
||||
if [ -z "${RELEASE_ID}" ]; then
|
||||
echo "Failed to create or fetch release"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for ARCHIVE in dist/*; do
|
||||
[ -e "${ARCHIVE}" ] || continue
|
||||
NAME=$(basename "${ARCHIVE}")
|
||||
case "${NAME}" in
|
||||
*.tar.gz) CONTENT_TYPE="application/gzip" ;;
|
||||
*.deb) CONTENT_TYPE="application/vnd.debian.binary-package" ;;
|
||||
*) CONTENT_TYPE="application/octet-stream" ;;
|
||||
esac
|
||||
curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: ${CONTENT_TYPE}" \
|
||||
--data-binary "@${ARCHIVE}" \
|
||||
"${API}/releases/${RELEASE_ID}/assets?name=${NAME}"
|
||||
echo "Uploaded ${NAME}"
|
||||
done
|
||||
|
||||
- name: Update APT repository
|
||||
working-directory: src
|
||||
run: |
|
||||
VERSION=${{ github.ref_name }}
|
||||
|
||||
git clone ssh://git@git-ssh.janvete.com:554/seth/apt.git apt-repo
|
||||
cp dist/*.deb apt-repo/
|
||||
|
||||
cd apt-repo
|
||||
|
||||
# Remove any corrupted .deb files left from previous failed runs
|
||||
for f in *.deb; do
|
||||
[ -e "$f" ] || continue
|
||||
if ! dpkg-deb -I "$f" >/dev/null 2>&1; then
|
||||
echo "Removing corrupted package: $f"
|
||||
rm -f "$f"
|
||||
fi
|
||||
done
|
||||
|
||||
dpkg-scanpackages . > Packages
|
||||
gzip -k -f Packages
|
||||
|
||||
cat > Release << RELEASE
|
||||
Origin: janvete
|
||||
Label: janvete
|
||||
Suite: stable
|
||||
Codename: stable
|
||||
Version: 1.0
|
||||
Architectures: amd64
|
||||
Components: main
|
||||
Description: janvete tools APT repository
|
||||
Date: $(date -Ru)
|
||||
RELEASE
|
||||
|
||||
{
|
||||
echo "SHA256:"
|
||||
for f in Packages Packages.gz *.deb; do
|
||||
[ -e "$f" ] || continue
|
||||
printf " %s %16d %s\n" "$(sha256sum "$f" | cut -d' ' -f1)" "$(stat -c%s "$f")" "$f"
|
||||
done
|
||||
} >> Release
|
||||
|
||||
git config user.email "forgejo-actions[bot]@janvete.com"
|
||||
git config user.name "forgejo-actions[bot]"
|
||||
git add -A
|
||||
git commit -m "chore: add lines ${VERSION}"
|
||||
git push
|
||||
131
Cargo.lock
generated
131
Cargo.lock
generated
|
|
@ -17,15 +17,6 @@ version = "0.2.21"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "1.0.0"
|
||||
|
|
@ -175,16 +166,6 @@ dependencies = [
|
|||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dad887fd958be91b5098c0248def011f4523ab786cd411be668777e55063501f"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
|
|
@ -197,19 +178,6 @@ version = "0.2.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.1"
|
||||
|
|
@ -279,12 +247,6 @@ dependencies = [
|
|||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
|
|
@ -513,12 +475,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||
|
||||
[[package]]
|
||||
name = "finl_unicode"
|
||||
version = "1.4.0"
|
||||
|
|
@ -662,30 +618,6 @@ version = "0.4.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.3.0"
|
||||
|
|
@ -825,10 +757,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "lines"
|
||||
version = "0.1.21"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chrono",
|
||||
"clap",
|
||||
"crossterm",
|
||||
"directories",
|
||||
|
|
@ -1479,12 +1409,6 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.18"
|
||||
|
|
@ -2048,65 +1972,12 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.59.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
|
|
|
|||
23
Cargo.toml
23
Cargo.toml
|
|
@ -1,33 +1,12 @@
|
|||
[package]
|
||||
name = "lines"
|
||||
version = "0.1.21"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["janvete"]
|
||||
description = "TUI for running frequently used commands"
|
||||
license = "MIT"
|
||||
repository = "https://git.janvete.com/seth/lines"
|
||||
homepage = "https://git.janvete.com/seth/lines"
|
||||
keywords = ["cli", "tui", "ssh", "commands"]
|
||||
categories = ["command-line-utilities"]
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.22.1"
|
||||
chrono = "0.4.45"
|
||||
clap = { version = "4.6.1", features = ["derive"] }
|
||||
crossterm = "0.29.0"
|
||||
directories = "6.0.0"
|
||||
ratatui = "0.30.1"
|
||||
toml = "1.1.2"
|
||||
walkdir = "2.5.0"
|
||||
|
||||
|
||||
[package.metadata.deb]
|
||||
maintainer = "janvete <jan.vete@example.com>"
|
||||
copyright = "2026, janvete"
|
||||
extended-description = "TUI application for quickly running frequently used commands from markdown files."
|
||||
section = "utils"
|
||||
priority = "optional"
|
||||
assets = [
|
||||
["target/release/lines", "usr/bin/lines", "755"],
|
||||
["README.md", "usr/share/doc/lines/README.md", "644"],
|
||||
]
|
||||
|
|
|
|||
144
README.md
144
README.md
|
|
@ -1,145 +1,79 @@
|
|||
# lines
|
||||
|
||||
A TUI app for quickly running frequently used commands — ideal for SSH scripts, updates, and anything you run regularly from the terminal.
|
||||
TUI aplikace pro rychlé spouštění často používaných příkazů — ideální pro SSH skripty, aktualizace a cokoliv, co pouštíš pravidelně z terminálu.
|
||||
|
||||
## Installation
|
||||
|
||||
### macOS (Homebrew)
|
||||
## Instalace
|
||||
|
||||
```bash
|
||||
brew tap janvete/tools https://git.janvete.com/seth/homebrew-tools.git
|
||||
brew install lines
|
||||
brew install janvete/tools/lines
|
||||
```
|
||||
|
||||
### Debian / Ubuntu (APT)
|
||||
## Použití
|
||||
|
||||
```bash
|
||||
echo "deb [trusted=yes] https://git.janvete.com/seth/apt/raw/branch/main ./" | sudo tee /etc/apt/sources.list.d/janvete.list
|
||||
sudo apt update
|
||||
sudo apt install lines
|
||||
lines # otevře TUI
|
||||
lines --dir /cesta/k/datům # použije jinou datovou složku
|
||||
```
|
||||
|
||||
### From source
|
||||
## Struktura dat
|
||||
|
||||
```bash
|
||||
cargo install --git ssh://git@git-ssh.janvete.com:554/seth/lines
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
lines # opens the TUI
|
||||
lines --dir /path # use a different data directory
|
||||
```
|
||||
|
||||
## Data structure
|
||||
|
||||
Data is stored as plain `.md` files in `~/.lines`. Groups are subdirectories.
|
||||
Data jsou běžné `.md` soubory ve složce `~/.lines`. Skupiny = podsložky.
|
||||
|
||||
```
|
||||
~/.lines
|
||||
├── Servers
|
||||
│ └── web.md
|
||||
├── Synology
|
||||
│ └── dsmview.md
|
||||
└── Scripts
|
||||
└── update.md
|
||||
```
|
||||
|
||||
### `.md` format
|
||||
### Konfigurace
|
||||
|
||||
Each section starts with `# Command name`. Command lines follow the heading.
|
||||
|
||||
```markdown
|
||||
# Web server
|
||||
ssh admin@web.example.com
|
||||
|
||||
# Database
|
||||
ssh admin@db.example.com
|
||||
```
|
||||
|
||||
A section without command lines means "run all commands in this file".
|
||||
|
||||
```markdown
|
||||
# Run all
|
||||
|
||||
# Docker update
|
||||
ssh admin@host1.example.com /opt/app/update.sh
|
||||
ssh admin@host2.example.com /opt/app/update.sh
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Create `~/.lines/config.toml`:
|
||||
Vytvoř soubor `~/.lines/config.toml`:
|
||||
|
||||
```toml
|
||||
terminal = "Ghostty" # options: Terminal, Ghostty, iTerm
|
||||
shell = "zsh" # options: any shell name, default is taken from $SHELL
|
||||
terminal = "Ghostty" # možnosti: Terminal, Ghostty, iTerm
|
||||
```
|
||||
|
||||
The default terminal is `Terminal` (macOS Terminal.app). The default shell is detected from the `$SHELL` environment variable.
|
||||
Výchozí terminál je `Terminal` (macOS Terminál.app).
|
||||
|
||||
## Controls
|
||||
## Formát `.md`
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| `↑/↓` or `j/k` | move |
|
||||
| `←/→` or `h/l` | switch panel |
|
||||
| `Enter` | run selected command / all commands in the current terminal |
|
||||
| `/` | open global search across all commands |
|
||||
| `o` | open selected command / all commands in a new terminal window |
|
||||
| `c` | open custom command mode for the current file |
|
||||
| `e` | open current `.md` file in `$EDITOR` |
|
||||
| `r` | reload data |
|
||||
| `q` / `Esc` | quit |
|
||||
|
||||
## Custom command mode
|
||||
|
||||
Press `c` on a selected file to run a custom command against specific lines from that file.
|
||||
|
||||
For a file containing:
|
||||
Každá sekce začíná nadpisem `# Název příkazu`. Pod ním následují řádky příkazů.
|
||||
|
||||
```markdown
|
||||
# PVE1
|
||||
ssh root@host1.example.com
|
||||
# Sysel DSM
|
||||
dsmview ssh root@192.168.40.15
|
||||
|
||||
# PVE2
|
||||
ssh root@host2.example.com
|
||||
|
||||
# PVE3
|
||||
ssh root@host3.example.com
|
||||
# Johy DSM
|
||||
dsmview ssh root@192.168.51.3
|
||||
```
|
||||
|
||||
Press `c`, select lines with `Space`, type `lsblk`, and press `Enter`. `lines` will run:
|
||||
Sekce bez příkazů znamená "spustit všechny příkazy v tomto souboru".
|
||||
|
||||
```bash
|
||||
ssh root@host2.example.com lsblk
|
||||
ssh root@host3.example.com lsblk
|
||||
```markdown
|
||||
# Spustí vše
|
||||
|
||||
# Docker update
|
||||
ssh root@192.168.53.3 /opt/mealie/update.sh
|
||||
ssh root@192.168.53.5 /opt/yamtrack/update.sh
|
||||
```
|
||||
|
||||
Use `{}` as a placeholder if your lines are just addresses:
|
||||
## Ovládání
|
||||
|
||||
```bash
|
||||
ssh {} lsblk
|
||||
```
|
||||
| Klávesa | Akce |
|
||||
|---------|------|
|
||||
| `↑/↓` nebo `j/k` | pohyb v seznamu |
|
||||
| `←/→` nebo `h/l` | přepínání panelů |
|
||||
| `Enter` | spustí vybraný příkaz / všechny příkazy |
|
||||
| `e` | otevře aktuální `.md` soubor v `$EDITOR` |
|
||||
| `r` | znovu načte data ze složky |
|
||||
| `q` nebo `Esc` | ukončí aplikaci |
|
||||
|
||||
Variables like `$HOME` or `$USER` are treated as remote-shell variables, so they are expanded on the target host, not by your local shell.
|
||||
## Zálohování
|
||||
|
||||
## Global search
|
||||
Celá datová složka `~/.lines` je obyčejný text — stačí ji zkopírovat na disk, do Gitu nebo iCloudu. Na novém Macu ji přeneseš a `lines` ji rovnou načte.
|
||||
|
||||
Press `/` to search across all commands, files, groups, and section names. Type your query, use `↑/↓` to select a result, and press `Enter` to run it.
|
||||
|
||||
## History
|
||||
|
||||
Every command run through `lines` is appended to `~/.lines/history.log`:
|
||||
|
||||
```
|
||||
2026-06-15 08:30:15 [Servers/web.md] Main server: ssh admin@web.example.com
|
||||
2026-06-15 08:31:02 [Scripts/update.md] Run all: ssh admin@host1.example.com /opt/app/update.sh; ssh admin@host2.example.com /opt/app/update.sh
|
||||
```
|
||||
|
||||
## Backup
|
||||
|
||||
The entire `~/.lines` folder is plain text. Copy it to a disk, Git repo, or iCloud. On a new Mac, move it to the same location and `lines` works immediately.
|
||||
|
||||
## License
|
||||
## Licence
|
||||
|
||||
MIT
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Run all
|
||||
# Spustí vše
|
||||
|
||||
# Docker update
|
||||
ssh admin@host1.example.com /opt/app/update.sh
|
||||
ssh admin@host2.example.com /opt/app/update.sh
|
||||
ssh root@192.168.53.3 /opt/mealie/update.sh
|
||||
ssh root@192.168.53.5 /opt/yamtrack/update.sh
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
# Main server
|
||||
ssh admin@web.example.com
|
||||
|
||||
# Backup server
|
||||
ssh admin@backup.example.com
|
||||
5
examples/Synology/dsmview.md
Normal file
5
examples/Synology/dsmview.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Sysel DSM
|
||||
dsmview ssh root@192.168.40.15
|
||||
|
||||
# Johy DSM
|
||||
dsmview ssh root@192.168.51.3
|
||||
226
src/app.rs
226
src/app.rs
|
|
@ -1,142 +1,8 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use ratatui::widgets::ListState;
|
||||
|
||||
use crate::config::Terminal;
|
||||
use crate::parser::{load_groups, CommandFile, Group, Section};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Screen {
|
||||
Main,
|
||||
Custom,
|
||||
Search,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SearchResult {
|
||||
pub group: String,
|
||||
pub file: String,
|
||||
pub section: String,
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SearchState {
|
||||
pub query: String,
|
||||
pub results: Vec<SearchResult>,
|
||||
pub cursor: usize,
|
||||
pub list_state: ListState,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PendingCommand {
|
||||
pub group: String,
|
||||
pub file: String,
|
||||
pub section: String,
|
||||
pub commands: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CustomFocus {
|
||||
Lines,
|
||||
Input,
|
||||
PreCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CustomLine {
|
||||
pub section: String,
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CustomState {
|
||||
pub lines: Vec<CustomLine>,
|
||||
pub selected: Vec<bool>,
|
||||
pub cursor: usize,
|
||||
pub focus: CustomFocus,
|
||||
pub command: String,
|
||||
pub pre_command: String,
|
||||
pub list_state: ListState,
|
||||
}
|
||||
|
||||
impl CustomState {
|
||||
pub fn from_file(file: &CommandFile) -> Self {
|
||||
let mut lines = Vec::new();
|
||||
for section in &file.sections {
|
||||
if section.is_run_all() {
|
||||
continue;
|
||||
}
|
||||
for cmd in §ion.commands {
|
||||
lines.push(CustomLine {
|
||||
section: section.title.clone(),
|
||||
command: cmd.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
let selected = vec![false; lines.len()];
|
||||
let mut list_state = ListState::default();
|
||||
list_state.select(Some(0));
|
||||
CustomState {
|
||||
lines,
|
||||
selected,
|
||||
cursor: 0,
|
||||
focus: CustomFocus::Lines,
|
||||
command: String::new(),
|
||||
pre_command: String::new(),
|
||||
list_state,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle(&mut self) {
|
||||
if self.focus != CustomFocus::Lines {
|
||||
return;
|
||||
}
|
||||
if let Some(s) = self.selected.get_mut(self.cursor) {
|
||||
*s = !*s;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
if !self.lines.is_empty() && self.focus == CustomFocus::Lines {
|
||||
self.cursor = (self.cursor + 1) % self.lines.len();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn previous(&mut self) {
|
||||
if !self.lines.is_empty() && self.focus == CustomFocus::Lines {
|
||||
self.cursor = self.cursor.checked_sub(1).unwrap_or(self.lines.len() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selected_lines(&self) -> Vec<String> {
|
||||
self.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(i, _)| self.selected.get(*i).copied().unwrap_or(false))
|
||||
.map(|(_, line)| line.command.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn cycle_focus(&mut self) {
|
||||
self.focus = match self.focus {
|
||||
CustomFocus::Lines => CustomFocus::Input,
|
||||
CustomFocus::Input => CustomFocus::PreCommand,
|
||||
CustomFocus::PreCommand => CustomFocus::Lines,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn toggle_all(&mut self) {
|
||||
if self.lines.is_empty() {
|
||||
return;
|
||||
}
|
||||
let all_selected = self.selected.iter().all(|s| *s);
|
||||
for s in &mut self.selected {
|
||||
*s = !all_selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Focus {
|
||||
Groups,
|
||||
|
|
@ -147,48 +13,26 @@ pub enum Focus {
|
|||
pub struct App {
|
||||
pub data_dir: PathBuf,
|
||||
pub terminal: Terminal,
|
||||
pub shell: String,
|
||||
pub groups: Vec<Group>,
|
||||
pub group_index: usize,
|
||||
pub file_index: usize,
|
||||
pub section_index: usize,
|
||||
pub focus: Focus,
|
||||
pub screen: Screen,
|
||||
pub custom_state: Option<CustomState>,
|
||||
pub search_state: Option<SearchState>,
|
||||
pub pending_command: Option<PendingCommand>,
|
||||
pub message: Option<String>,
|
||||
pub group_list_state: ListState,
|
||||
pub file_list_state: ListState,
|
||||
pub section_list_state: ListState,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new(data_dir: PathBuf, terminal: Terminal, shell: String) -> Self {
|
||||
pub fn new(data_dir: PathBuf, terminal: Terminal) -> Self {
|
||||
let groups = load_groups(&data_dir);
|
||||
let mut group_list_state = ListState::default();
|
||||
let mut file_list_state = ListState::default();
|
||||
let mut section_list_state = ListState::default();
|
||||
group_list_state.select(Some(0));
|
||||
file_list_state.select(Some(0));
|
||||
section_list_state.select(Some(0));
|
||||
App {
|
||||
data_dir,
|
||||
terminal,
|
||||
shell,
|
||||
groups,
|
||||
group_index: 0,
|
||||
file_index: 0,
|
||||
section_index: 0,
|
||||
focus: Focus::Groups,
|
||||
screen: Screen::Main,
|
||||
custom_state: None,
|
||||
search_state: None,
|
||||
pending_command: None,
|
||||
message: None,
|
||||
group_list_state,
|
||||
file_list_state,
|
||||
section_list_state,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -199,52 +43,6 @@ impl App {
|
|||
self.section_index = self.section_index.min(self.current_sections().len().saturating_sub(1));
|
||||
}
|
||||
|
||||
pub fn enter_custom(&mut self) {
|
||||
if let Some(file) = self.current_file() {
|
||||
self.custom_state = Some(CustomState::from_file(file));
|
||||
self.screen = Screen::Custom;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exit_custom(&mut self) {
|
||||
self.screen = Screen::Main;
|
||||
self.custom_state = None;
|
||||
}
|
||||
|
||||
pub fn enter_search(&mut self) {
|
||||
let results = build_search_index(&self.groups);
|
||||
let mut list_state = ListState::default();
|
||||
list_state.select(Some(0));
|
||||
self.search_state = Some(SearchState {
|
||||
query: String::new(),
|
||||
results,
|
||||
cursor: 0,
|
||||
list_state,
|
||||
});
|
||||
self.screen = Screen::Search;
|
||||
}
|
||||
|
||||
pub fn exit_search(&mut self) {
|
||||
self.screen = Screen::Main;
|
||||
self.search_state = None;
|
||||
}
|
||||
|
||||
pub fn update_search(&mut self) {
|
||||
if let Some(state) = self.search_state.as_mut() {
|
||||
let query = state.query.to_lowercase();
|
||||
state.results = build_search_index(&self.groups)
|
||||
.into_iter()
|
||||
.filter(|r| {
|
||||
r.group.to_lowercase().contains(&query)
|
||||
|| r.file.to_lowercase().contains(&query)
|
||||
|| r.section.to_lowercase().contains(&query)
|
||||
|| r.command.to_lowercase().contains(&query)
|
||||
})
|
||||
.collect();
|
||||
state.cursor = state.cursor.min(state.results.len().saturating_sub(1));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn current_group(&self) -> Option<&Group> {
|
||||
self.groups.get(self.group_index)
|
||||
}
|
||||
|
|
@ -337,25 +135,3 @@ impl App {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn build_search_index(groups: &[Group]) -> Vec<SearchResult> {
|
||||
let mut results = Vec::new();
|
||||
for group in groups {
|
||||
for file in &group.files {
|
||||
for section in &file.sections {
|
||||
if section.is_run_all() {
|
||||
continue;
|
||||
}
|
||||
for command in §ion.commands {
|
||||
results.push(SearchResult {
|
||||
group: group.name.clone(),
|
||||
file: file.name.clone(),
|
||||
section: section.title.clone(),
|
||||
command: command.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
results
|
||||
}
|
||||
|
|
|
|||
108
src/commands.rs
108
src/commands.rs
|
|
@ -1,26 +1,13 @@
|
|||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||
|
||||
use crate::config::Terminal;
|
||||
use crate::logger;
|
||||
use crate::parser::{CommandFile, Section};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn run_section(
|
||||
section: &Section,
|
||||
file: &CommandFile,
|
||||
terminal: &Terminal,
|
||||
shell: &str,
|
||||
data_dir: &Path,
|
||||
group_name: &str,
|
||||
file_name: &str,
|
||||
section_name: &str,
|
||||
) {
|
||||
pub fn run_section(section: &Section, file: &CommandFile, terminal: &Terminal, data_dir: &Path) {
|
||||
let commands = if section.is_run_all() {
|
||||
file.sections
|
||||
.iter()
|
||||
|
|
@ -35,24 +22,20 @@ pub fn run_section(
|
|||
return;
|
||||
}
|
||||
|
||||
logger::log_run(
|
||||
data_dir,
|
||||
group_name,
|
||||
file_name,
|
||||
section_name,
|
||||
&commands,
|
||||
true,
|
||||
);
|
||||
|
||||
match terminal {
|
||||
Terminal::Ghostty => run_in_ghostty(&commands, shell),
|
||||
_ => run_via_script(&commands, terminal, shell, data_dir),
|
||||
}
|
||||
let script = build_script(&commands);
|
||||
execute_in_terminal(&script, terminal, data_dir);
|
||||
}
|
||||
|
||||
fn run_via_script(commands: &[String], terminal: &Terminal, shell: &str, data_dir: &Path) {
|
||||
let script = commands.join("\n");
|
||||
let run_dir = data_dir.join(".run");
|
||||
fn build_script(commands: &[String]) -> String {
|
||||
commands.join("\n")
|
||||
}
|
||||
|
||||
fn script_dir(data_dir: &Path) -> PathBuf {
|
||||
data_dir.join(".run")
|
||||
}
|
||||
|
||||
fn execute_in_terminal(script: &str, terminal: &Terminal, data_dir: &Path) {
|
||||
let run_dir = script_dir(data_dir);
|
||||
if fs::create_dir_all(&run_dir).is_err() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -77,56 +60,50 @@ fn run_via_script(commands: &[String], terminal: &Terminal, shell: &str, data_di
|
|||
let _ = fs::set_permissions(&script_path, fs::Permissions::from_mode(0o755));
|
||||
|
||||
match terminal {
|
||||
Terminal::Iterm => run_in_iterm(&script_path, shell),
|
||||
Terminal::Builtin => run_in_terminal_app(&script_path, shell),
|
||||
Terminal::Ghostty => unreachable!(),
|
||||
Terminal::Ghostty => run_in_ghostty(&script_path),
|
||||
Terminal::Iterm => run_in_iterm(&script_path),
|
||||
Terminal::Builtin => run_in_terminal_app(&script_path),
|
||||
}
|
||||
}
|
||||
|
||||
fn run_in_ghostty(commands: &[String], shell: &str) {
|
||||
let script = commands.join("\n");
|
||||
let encoded = STANDARD.encode(script);
|
||||
let shell_command = format!("echo {} | base64 -D | {}", encoded, shell);
|
||||
fn run_in_terminal_app(script_path: &Path) {
|
||||
let path_str = script_path.to_string_lossy();
|
||||
let applescript = format!(
|
||||
r#"tell application "Terminal"
|
||||
do script "clear; bash {}"
|
||||
activate
|
||||
end tell"#,
|
||||
escape_applescript(&path_str)
|
||||
);
|
||||
|
||||
let _ = Command::new("osascript")
|
||||
.arg("-e")
|
||||
.arg(applescript)
|
||||
.spawn();
|
||||
}
|
||||
|
||||
fn run_in_ghostty(script_path: &Path) {
|
||||
let path_str = script_path.to_string_lossy();
|
||||
let _ = Command::new("open")
|
||||
.arg("-na")
|
||||
.arg("Ghostty")
|
||||
.arg("--args")
|
||||
.arg("-e")
|
||||
.arg(shell)
|
||||
.arg("-c")
|
||||
.arg(shell_command)
|
||||
.arg("bash")
|
||||
.arg(path_str.as_ref())
|
||||
.spawn();
|
||||
}
|
||||
|
||||
fn run_in_terminal_app(script_path: &Path, shell: &str) {
|
||||
let path_str = script_path.to_string_lossy();
|
||||
let applescript = format!(
|
||||
r#"tell application "Terminal"
|
||||
do script "clear; {} {}"
|
||||
activate
|
||||
end tell"#,
|
||||
shell,
|
||||
escape_applescript(&path_str)
|
||||
);
|
||||
|
||||
let _ = Command::new("osascript")
|
||||
.arg("-e")
|
||||
.arg(applescript)
|
||||
.spawn();
|
||||
}
|
||||
|
||||
fn run_in_iterm(script_path: &Path, shell: &str) {
|
||||
fn run_in_iterm(script_path: &Path) {
|
||||
let path_str = script_path.to_string_lossy();
|
||||
let applescript = format!(
|
||||
r#"tell application "iTerm"
|
||||
create window with default profile
|
||||
tell current session of current window
|
||||
write text "clear; {} {}"
|
||||
write text "clear; bash {}"
|
||||
end tell
|
||||
activate
|
||||
end tell"#,
|
||||
shell,
|
||||
escape_applescript(&path_str)
|
||||
);
|
||||
|
||||
|
|
@ -136,7 +113,7 @@ end tell"#,
|
|||
.spawn();
|
||||
}
|
||||
|
||||
pub fn edit_file(path: &Path, terminal: &Terminal, shell: &str) {
|
||||
pub fn edit_file(path: &Path, terminal: &Terminal) {
|
||||
let editor = std::env::var("EDITOR").unwrap_or_else(|_| "nano".to_string());
|
||||
|
||||
match terminal {
|
||||
|
|
@ -146,14 +123,13 @@ pub fn edit_file(path: &Path, terminal: &Terminal, shell: &str) {
|
|||
.arg("Ghostty")
|
||||
.arg("--args")
|
||||
.arg("-e")
|
||||
.arg(shell)
|
||||
.arg("bash")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"cd {} && {} {}; exec {}",
|
||||
"cd {} && {} {}; exec bash",
|
||||
escape_shell(&std::env::current_dir().unwrap_or_default().to_string_lossy()),
|
||||
escape_shell(&editor),
|
||||
escape_shell(&path.to_string_lossy()),
|
||||
shell
|
||||
escape_shell(&path.to_string_lossy())
|
||||
))
|
||||
.spawn();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub data_dir: PathBuf,
|
||||
pub terminal: Terminal,
|
||||
pub shell: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
|
|
@ -30,12 +30,8 @@ impl Terminal {
|
|||
impl Config {
|
||||
pub fn new(data_dir: Option<PathBuf>) -> Self {
|
||||
let data_dir = data_dir.unwrap_or_else(default_data_dir);
|
||||
let (terminal, shell) = load_preferences(&data_dir);
|
||||
Config {
|
||||
data_dir,
|
||||
terminal,
|
||||
shell,
|
||||
}
|
||||
let terminal = load_terminal_preference(&data_dir);
|
||||
Config { data_dir, terminal }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,39 +41,19 @@ fn default_data_dir() -> PathBuf {
|
|||
.unwrap_or_else(|| PathBuf::from(".lines"))
|
||||
}
|
||||
|
||||
fn default_shell() -> String {
|
||||
std::env::var("SHELL")
|
||||
.ok()
|
||||
.and_then(|s| {
|
||||
Path::new(&s)
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.map(String::from)
|
||||
})
|
||||
.unwrap_or_else(|| "zsh".to_string())
|
||||
}
|
||||
|
||||
fn load_preferences(data_dir: &Path) -> (Terminal, String) {
|
||||
fn load_terminal_preference(data_dir: &Path) -> Terminal {
|
||||
let config_path = data_dir.join("config.toml");
|
||||
let content = match fs::read_to_string(&config_path) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return (Terminal::default(), default_shell()),
|
||||
Err(_) => return Terminal::default(),
|
||||
};
|
||||
|
||||
match toml::from_str::<toml::Value>(&content) {
|
||||
Ok(value) => {
|
||||
let terminal = value
|
||||
.get("terminal")
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(Terminal::from_str)
|
||||
.unwrap_or_default();
|
||||
let shell = value
|
||||
.get("shell")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(String::from)
|
||||
.unwrap_or_else(default_shell);
|
||||
(terminal, shell)
|
||||
}
|
||||
Err(_) => (Terminal::default(), default_shell()),
|
||||
Ok(value) => value
|
||||
.get("terminal")
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(Terminal::from_str)
|
||||
.unwrap_or_default(),
|
||||
Err(_) => Terminal::default(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
182
src/custom.rs
182
src/custom.rs
|
|
@ -1,182 +0,0 @@
|
|||
use crate::app::CustomState;
|
||||
|
||||
pub fn build_commands(state: &CustomState) -> Vec<String> {
|
||||
let command = state.command.trim();
|
||||
let pre_command = state.pre_command.trim();
|
||||
|
||||
if command.is_empty() && pre_command.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let selected = state.selected_lines();
|
||||
if selected.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let prefix = if pre_command.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("{} ", pre_command)
|
||||
};
|
||||
|
||||
selected
|
||||
.iter()
|
||||
.map(|line| {
|
||||
let line = line.trim();
|
||||
let built = if command.is_empty() {
|
||||
line.to_string()
|
||||
} else if command.contains("{}") {
|
||||
escape_dollars(&command.replace("{}", line))
|
||||
} else {
|
||||
let escaped = escape_dollars(command).replace('"', "\\\"");
|
||||
format!("{} \"{}\"", line, escaped)
|
||||
};
|
||||
format!("{}{}", prefix, built)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Escape `$` as `\$` unless it is already escaped, so that variables are
|
||||
/// expanded by the remote shell rather than the local one when the built
|
||||
/// command is passed to `ssh`.
|
||||
fn escape_dollars(command: &str) -> String {
|
||||
let mut result = String::with_capacity(command.len());
|
||||
let mut prev_backslash = false;
|
||||
for c in command.chars() {
|
||||
if c == '$' && !prev_backslash {
|
||||
result.push('\\');
|
||||
}
|
||||
result.push(c);
|
||||
prev_backslash = c == '\\' && !prev_backslash;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::{CustomLine, CustomState};
|
||||
|
||||
fn make_state(lines: Vec<&str>, selected: Vec<bool>, command: &str, pre_command: &str) -> CustomState {
|
||||
let mut list_state = ratatui::widgets::ListState::default();
|
||||
list_state.select(Some(0));
|
||||
CustomState {
|
||||
lines: lines
|
||||
.into_iter()
|
||||
.map(|c| CustomLine {
|
||||
section: "test".to_string(),
|
||||
command: c.to_string(),
|
||||
})
|
||||
.collect(),
|
||||
selected,
|
||||
cursor: 0,
|
||||
focus: crate::app::CustomFocus::Lines,
|
||||
command: command.to_string(),
|
||||
pre_command: pre_command.to_string(),
|
||||
list_state,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_append() {
|
||||
let state = make_state(
|
||||
vec!["ssh root@ip1", "ssh root@ip2", "ssh root@ip3"],
|
||||
vec![false, true, true],
|
||||
"lsblk",
|
||||
"",
|
||||
);
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec!["ssh root@ip2 \"lsblk\"", "ssh root@ip3 \"lsblk\""]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_placeholder() {
|
||||
let state = make_state(vec!["root@ip1", "root@ip2"], vec![true, true], "ssh {} lsblk", "");
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec!["ssh root@ip1 lsblk", "ssh root@ip2 lsblk"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_empty_selection() {
|
||||
let state = make_state(vec!["ssh root@ip1"], vec![false], "lsblk", "");
|
||||
assert!(build_commands(&state).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_pre_command() {
|
||||
let state = make_state(
|
||||
vec!["ssh root@ip1", "ssh root@ip2"],
|
||||
vec![true, true],
|
||||
"ping",
|
||||
"lview",
|
||||
);
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec![
|
||||
"lview ssh root@ip1 \"ping\"",
|
||||
"lview ssh root@ip2 \"ping\""
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_pre_command_placeholder() {
|
||||
let state = make_state(
|
||||
vec!["root@ip1", "root@ip2"],
|
||||
vec![true, true],
|
||||
"ssh {} lsblk",
|
||||
"lview",
|
||||
);
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec!["lview ssh root@ip1 lsblk", "lview ssh root@ip2 lsblk"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_pre_command_only() {
|
||||
let state = make_state(vec!["ssh root@ip1", "ssh root@ip2"], vec![false, true], "", "lview");
|
||||
assert_eq!(build_commands(&state), vec!["lview ssh root@ip2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_escapes_dollar_variables() {
|
||||
let state = make_state(
|
||||
vec!["ssh root@ip1"],
|
||||
vec![true],
|
||||
"echo $HOME && echo $USER",
|
||||
"",
|
||||
);
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec!["ssh root@ip1 \"echo \\$HOME && echo \\$USER\""]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_preserves_already_escaped_dollars() {
|
||||
let state = make_state(
|
||||
vec!["ssh root@ip1"],
|
||||
vec![true],
|
||||
"echo \\$HOME",
|
||||
"",
|
||||
);
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec!["ssh root@ip1 \"echo \\$HOME\""]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_placeholder_escapes_dollars() {
|
||||
let state = make_state(vec!["root@ip1"], vec![true], "ssh {} echo $HOSTNAME", "");
|
||||
assert_eq!(
|
||||
build_commands(&state),
|
||||
vec!["ssh root@ip1 echo \\$HOSTNAME"]
|
||||
);
|
||||
}
|
||||
}
|
||||
300
src/events.rs
300
src/events.rs
|
|
@ -1,25 +1,20 @@
|
|||
use crossterm::event::{self, Event, KeyCode, KeyEventKind, MouseEventKind};
|
||||
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::app::{App, CustomFocus, CustomState, PendingCommand, Screen};
|
||||
use crate::app::App;
|
||||
use crate::commands::{edit_file, run_section};
|
||||
use crate::custom::build_commands;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AppEvent {
|
||||
Tick,
|
||||
Key(event::KeyEvent),
|
||||
Mouse(event::MouseEvent),
|
||||
Paste(String),
|
||||
}
|
||||
|
||||
pub fn poll_event(timeout: Duration) -> io::Result<Option<AppEvent>> {
|
||||
if event::poll(timeout)? {
|
||||
match event::read()? {
|
||||
Event::Key(key) => Ok(Some(AppEvent::Key(key))),
|
||||
Event::Mouse(mouse) => Ok(Some(AppEvent::Mouse(mouse))),
|
||||
Event::Paste(text) => Ok(Some(AppEvent::Paste(text))),
|
||||
_ => Ok(Some(AppEvent::Tick)),
|
||||
}
|
||||
} else {
|
||||
|
|
@ -34,283 +29,26 @@ pub fn handle_event(app: &mut App, event: AppEvent) -> bool {
|
|||
if key.kind != KeyEventKind::Press {
|
||||
return true;
|
||||
}
|
||||
|
||||
match app.screen {
|
||||
Screen::Main => handle_main_event(app, key),
|
||||
Screen::Custom => handle_custom_event(app, key),
|
||||
Screen::Search => handle_search_event(app, key),
|
||||
}
|
||||
}
|
||||
AppEvent::Mouse(mouse) => match mouse.kind {
|
||||
MouseEventKind::ScrollDown => {
|
||||
scroll_down(app);
|
||||
true
|
||||
}
|
||||
MouseEventKind::ScrollUp => {
|
||||
scroll_up(app);
|
||||
true
|
||||
}
|
||||
_ => true,
|
||||
},
|
||||
AppEvent::Paste(text) => handle_paste_event(app, &text),
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll_down(app: &mut App) {
|
||||
match app.screen {
|
||||
Screen::Main => app.next(),
|
||||
Screen::Custom => {
|
||||
if let Some(state) = app.custom_state.as_mut() {
|
||||
state.next();
|
||||
}
|
||||
}
|
||||
Screen::Search => {
|
||||
if let Some(state) = app.search_state.as_mut() && !state.results.is_empty() {
|
||||
state.cursor = (state.cursor + 1) % state.results.len();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll_up(app: &mut App) {
|
||||
match app.screen {
|
||||
Screen::Main => app.previous(),
|
||||
Screen::Custom => {
|
||||
if let Some(state) = app.custom_state.as_mut() {
|
||||
state.previous();
|
||||
}
|
||||
}
|
||||
Screen::Search => {
|
||||
if let Some(state) = app.search_state.as_mut() && !state.results.is_empty() {
|
||||
state.cursor = state.cursor.checked_sub(1).unwrap_or(state.results.len() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_main_event(app: &mut App, key: event::KeyEvent) -> bool {
|
||||
match key.code {
|
||||
KeyCode::Char('q') | KeyCode::Esc => return false,
|
||||
KeyCode::Down => app.next(),
|
||||
KeyCode::Up => app.previous(),
|
||||
KeyCode::Left => app.focus_left(),
|
||||
KeyCode::Right => app.focus_right(),
|
||||
KeyCode::Char('r') => app.reload(),
|
||||
KeyCode::Char('e') => {
|
||||
if let Some(file) = app.current_file() {
|
||||
edit_file(&file.path, &app.terminal, &app.shell);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('c') => {
|
||||
app.enter_custom();
|
||||
}
|
||||
KeyCode::Char('/') => {
|
||||
app.enter_search();
|
||||
}
|
||||
KeyCode::Char('o') => {
|
||||
if let (Some(section), Some(file), Some(group)) =
|
||||
(app.current_section(), app.current_file(), app.current_group())
|
||||
{
|
||||
run_section(
|
||||
section,
|
||||
file,
|
||||
&app.terminal,
|
||||
&app.shell,
|
||||
&app.data_dir,
|
||||
&group.name,
|
||||
&file.name,
|
||||
§ion.title,
|
||||
);
|
||||
}
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let (Some(section), Some(file), Some(group)) =
|
||||
(app.current_section(), app.current_file(), app.current_group())
|
||||
{
|
||||
let commands = if section.is_run_all() {
|
||||
file.sections
|
||||
.iter()
|
||||
.filter(|s| !s.is_run_all())
|
||||
.flat_map(|s| s.commands.clone())
|
||||
.collect()
|
||||
} else {
|
||||
section.commands.clone()
|
||||
};
|
||||
if !commands.is_empty() {
|
||||
app.pending_command = Some(PendingCommand {
|
||||
group: group.name.clone(),
|
||||
file: file.name.clone(),
|
||||
section: section.title.clone(),
|
||||
commands,
|
||||
});
|
||||
return false;
|
||||
match key.code {
|
||||
KeyCode::Char('q') | KeyCode::Esc => return false,
|
||||
KeyCode::Char('j') | KeyCode::Down => app.next(),
|
||||
KeyCode::Char('k') | KeyCode::Up => app.previous(),
|
||||
KeyCode::Char('h') | KeyCode::Left => app.focus_left(),
|
||||
KeyCode::Char('l') | KeyCode::Right => app.focus_right(),
|
||||
KeyCode::Char('r') => app.reload(),
|
||||
KeyCode::Char('e') => {
|
||||
if let Some(file) = app.current_file() {
|
||||
edit_file(&file.path, &app.terminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn handle_custom_event(app: &mut App, key: event::KeyEvent) -> bool {
|
||||
let Some(state) = app.custom_state.as_mut() else {
|
||||
app.exit_custom();
|
||||
return true;
|
||||
};
|
||||
|
||||
match key.code {
|
||||
KeyCode::Esc | KeyCode::Char('q') => {
|
||||
app.exit_custom();
|
||||
}
|
||||
KeyCode::Tab => {
|
||||
state.cycle_focus();
|
||||
}
|
||||
KeyCode::Down => {
|
||||
if state.focus == CustomFocus::Lines {
|
||||
state.next();
|
||||
}
|
||||
}
|
||||
KeyCode::Up => {
|
||||
if state.focus == CustomFocus::Lines {
|
||||
state.previous();
|
||||
}
|
||||
}
|
||||
KeyCode::Char(' ') => {
|
||||
if state.focus == CustomFocus::Lines {
|
||||
state.toggle();
|
||||
} else {
|
||||
push_to_active_input(state, ' ');
|
||||
}
|
||||
}
|
||||
KeyCode::Char('a') => {
|
||||
if state.focus == CustomFocus::Lines {
|
||||
state.toggle_all();
|
||||
} else {
|
||||
push_to_active_input(state, 'a');
|
||||
}
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
pop_from_active_input(state);
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if state.focus == CustomFocus::Input || state.focus == CustomFocus::PreCommand {
|
||||
let commands = build_commands(state);
|
||||
if !commands.is_empty()
|
||||
&& let (Some(file), Some(group)) = (app.current_file(), app.current_group())
|
||||
{
|
||||
app.pending_command = Some(PendingCommand {
|
||||
group: group.name.clone(),
|
||||
file: file.name.clone(),
|
||||
section: "custom".to_string(),
|
||||
commands,
|
||||
});
|
||||
return false;
|
||||
KeyCode::Enter => {
|
||||
if let (Some(section), Some(file)) = (app.current_section(), app.current_file()) {
|
||||
run_section(section, file, &app.terminal, &app.data_dir);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state.focus = CustomFocus::Input;
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
if state.focus == CustomFocus::Lines {
|
||||
state.command.push(c);
|
||||
} else {
|
||||
push_to_active_input(state, c);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn push_to_active_input(state: &mut CustomState, c: char) {
|
||||
match state.focus {
|
||||
CustomFocus::Input => state.command.push(c),
|
||||
CustomFocus::PreCommand => state.pre_command.push(c),
|
||||
CustomFocus::Lines => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn pop_from_active_input(state: &mut CustomState) {
|
||||
match state.focus {
|
||||
CustomFocus::Input => {
|
||||
state.command.pop();
|
||||
}
|
||||
CustomFocus::PreCommand => {
|
||||
state.pre_command.pop();
|
||||
}
|
||||
CustomFocus::Lines => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_paste_event(app: &mut App, text: &str) -> bool {
|
||||
match app.screen {
|
||||
Screen::Main => true,
|
||||
Screen::Custom => {
|
||||
let Some(state) = app.custom_state.as_mut() else {
|
||||
app.exit_custom();
|
||||
return true;
|
||||
};
|
||||
match state.focus {
|
||||
CustomFocus::Input => state.command.push_str(text),
|
||||
CustomFocus::PreCommand => state.pre_command.push_str(text),
|
||||
CustomFocus::Lines => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
Screen::Search => {
|
||||
let Some(state) = app.search_state.as_mut() else {
|
||||
app.exit_search();
|
||||
return true;
|
||||
};
|
||||
// Search queries are single-line; keep only the first pasted line.
|
||||
let query = text.lines().next().unwrap_or(text);
|
||||
state.query.push_str(query);
|
||||
app.update_search();
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_search_event(app: &mut App, key: event::KeyEvent) -> bool {
|
||||
let Some(state) = app.search_state.as_mut() else {
|
||||
app.exit_search();
|
||||
return true;
|
||||
};
|
||||
|
||||
match key.code {
|
||||
KeyCode::Esc | KeyCode::Char('q') => {
|
||||
app.exit_search();
|
||||
}
|
||||
KeyCode::Down => {
|
||||
if !state.results.is_empty() {
|
||||
state.cursor = (state.cursor + 1) % state.results.len();
|
||||
}
|
||||
}
|
||||
KeyCode::Up => {
|
||||
if !state.results.is_empty() {
|
||||
state.cursor = state.cursor.checked_sub(1).unwrap_or(state.results.len() - 1);
|
||||
}
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
state.query.pop();
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let Some(result) = state.results.get(state.cursor) {
|
||||
app.pending_command = Some(PendingCommand {
|
||||
group: result.group.clone(),
|
||||
file: result.file.clone(),
|
||||
section: result.section.clone(),
|
||||
commands: vec![result.command.clone()],
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
state.query.push(c);
|
||||
app.update_search();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
use std::fs::{self, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn log_run(
|
||||
data_dir: &Path,
|
||||
group: &str,
|
||||
file: &str,
|
||||
section: &str,
|
||||
commands: &[String],
|
||||
in_new_window: bool,
|
||||
) {
|
||||
let log_path = data_dir.join("history.log");
|
||||
|
||||
let timestamp = chrono::Local::now().format("%Y-%m-%d %H:%M:%S");
|
||||
let window_note = if in_new_window { " [new-window]" } else { "" };
|
||||
let commands_str = commands.join("; ");
|
||||
|
||||
let line = format!(
|
||||
"{} [{}/{}] {}{}: {}\n",
|
||||
timestamp, group, file, section, window_note, commands_str
|
||||
);
|
||||
|
||||
if let Some(parent) = log_path.parent() {
|
||||
let _ = fs::create_dir_all(parent);
|
||||
}
|
||||
|
||||
let mut file = match OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&log_path)
|
||||
{
|
||||
Ok(f) => f,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
let _ = file.write_all(line.as_bytes());
|
||||
}
|
||||
54
src/main.rs
54
src/main.rs
|
|
@ -1,22 +1,17 @@
|
|||
mod app;
|
||||
mod commands;
|
||||
mod config;
|
||||
mod custom;
|
||||
mod events;
|
||||
mod logger;
|
||||
mod parser;
|
||||
mod ui;
|
||||
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
|
||||
use clap::Parser;
|
||||
use crossterm::{
|
||||
event::{
|
||||
DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture,
|
||||
},
|
||||
event::{DisableMouseCapture, EnableMouseCapture},
|
||||
execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
|
|
@ -31,10 +26,10 @@ use crate::events::{handle_event, poll_event};
|
|||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "lines")]
|
||||
#[command(about = "TUI for running frequently used commands")]
|
||||
#[command(about = "TUI pro rychlé spouštění často používaných příkazů")]
|
||||
#[command(version)]
|
||||
struct Args {
|
||||
/// Path to the data directory (default: ~/.lines)
|
||||
/// Cesta k datové složce (výchozí: ~/.lines)
|
||||
#[arg(short, long)]
|
||||
dir: Option<PathBuf>,
|
||||
}
|
||||
|
|
@ -45,70 +40,47 @@ fn main() -> io::Result<()> {
|
|||
|
||||
// Ensure data directory exists
|
||||
if let Err(e) = std::fs::create_dir_all(&config.data_dir) {
|
||||
eprintln!(
|
||||
"Failed to create data directory {}: {}",
|
||||
config.data_dir.display(),
|
||||
e
|
||||
);
|
||||
eprintln!("Nepodařilo se vytvořit datovou složku {}: {}", config.data_dir.display(), e);
|
||||
}
|
||||
|
||||
let app = App::new(config.data_dir, config.terminal, config.shell);
|
||||
let app = App::new(config.data_dir, config.terminal);
|
||||
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = io::stdout();
|
||||
execute!(
|
||||
stdout,
|
||||
EnterAlternateScreen,
|
||||
EnableMouseCapture,
|
||||
EnableBracketedPaste
|
||||
)?;
|
||||
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
let app = run_app(&mut terminal, app)?;
|
||||
let res = run_app(&mut terminal, app);
|
||||
|
||||
disable_raw_mode()?;
|
||||
execute!(
|
||||
terminal.backend_mut(),
|
||||
LeaveAlternateScreen,
|
||||
DisableMouseCapture,
|
||||
DisableBracketedPaste
|
||||
DisableMouseCapture
|
||||
)?;
|
||||
terminal.show_cursor()?;
|
||||
|
||||
if let Some(pending) = app.pending_command {
|
||||
logger::log_run(
|
||||
&app.data_dir,
|
||||
&pending.group,
|
||||
&pending.file,
|
||||
&pending.section,
|
||||
&pending.commands,
|
||||
false,
|
||||
);
|
||||
run_in_current_terminal(&pending.commands, &app.shell);
|
||||
if let Err(err) = res {
|
||||
eprintln!("{}", err);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<App>
|
||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()>
|
||||
where
|
||||
io::Error: From<<B as Backend>::Error>,
|
||||
{
|
||||
let tick_rate = Duration::from_millis(100);
|
||||
|
||||
loop {
|
||||
terminal.draw(|f| ui::draw(f, &mut app))?;
|
||||
terminal.draw(|f| ui::draw(f, &app))?;
|
||||
|
||||
if let Some(event) = poll_event(tick_rate)?
|
||||
&& !handle_event(&mut app, event)
|
||||
{
|
||||
return Ok(app);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_in_current_terminal(commands: &[String], shell: &str) {
|
||||
let script = commands.join("\n");
|
||||
let _ = Command::new(shell).arg("-c").arg(script).status();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,10 +157,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_parse_markdown_run_all() {
|
||||
let input = "# Run all\n\n# Docker update\nssh admin@host1.example.com /opt/app/update.sh\nssh admin@host2.example.com /opt/app/update.sh\n";
|
||||
let input = "# Spustí vše\n\n# Docker update\nssh root@192.168.53.3 /opt/mealie/update.sh\nssh root@192.168.53.5 /opt/yamtrack/update.sh\n";
|
||||
let sections = parse_markdown(input);
|
||||
assert_eq!(sections.len(), 2);
|
||||
assert_eq!(sections[0].title, "Run all");
|
||||
assert_eq!(sections[0].title, "Spustí vše");
|
||||
assert!(sections[0].commands.is_empty());
|
||||
assert_eq!(sections[1].commands.len(), 2);
|
||||
}
|
||||
|
|
|
|||
204
src/ui.rs
204
src/ui.rs
|
|
@ -6,17 +6,9 @@ use ratatui::{
|
|||
Frame,
|
||||
};
|
||||
|
||||
use crate::app::{App, CustomFocus, Focus, Screen};
|
||||
use crate::app::{App, Focus};
|
||||
|
||||
pub fn draw(f: &mut Frame, app: &mut App) {
|
||||
match app.screen {
|
||||
Screen::Main => draw_main(f, app),
|
||||
Screen::Custom => draw_custom(f, app),
|
||||
Screen::Search => draw_search(f, app),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_main(f: &mut Frame, app: &mut App) {
|
||||
pub fn draw(f: &mut Frame, app: &App) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
|
|
@ -43,168 +35,7 @@ fn draw_main(f: &mut Frame, app: &mut App) {
|
|||
draw_status(f, app, chunks[2]);
|
||||
}
|
||||
|
||||
fn draw_custom(f: &mut Frame, app: &mut App) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([
|
||||
Constraint::Min(5),
|
||||
Constraint::Length(5),
|
||||
Constraint::Length(5),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.split(f.area());
|
||||
|
||||
let Some(state) = app.custom_state.as_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let items: Vec<ListItem> = state
|
||||
.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, line)| {
|
||||
let checked = if state.selected.get(i).copied().unwrap_or(false) {
|
||||
"[x]"
|
||||
} else {
|
||||
"[ ]"
|
||||
};
|
||||
let label = format!(
|
||||
"{} {} — {}",
|
||||
checked,
|
||||
line.command,
|
||||
line.section
|
||||
);
|
||||
let mut style = Style::default();
|
||||
if i == state.cursor && state.focus == CustomFocus::Lines {
|
||||
style = style
|
||||
.bg(Color::Blue)
|
||||
.fg(Color::Black)
|
||||
.add_modifier(Modifier::BOLD);
|
||||
}
|
||||
ListItem::new(label).style(style)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list_block = Block::default()
|
||||
.title(" Custom command — select lines with Space ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(if state.focus == CustomFocus::Lines {
|
||||
Style::default().fg(Color::Yellow)
|
||||
} else {
|
||||
Style::default().fg(Color::DarkGray)
|
||||
});
|
||||
let list = List::new(items).block(list_block);
|
||||
state.list_state.select(Some(state.cursor));
|
||||
f.render_stateful_widget(list, chunks[0], &mut state.list_state);
|
||||
|
||||
let input = Paragraph::new(state.command.as_str())
|
||||
.block(
|
||||
Block::default()
|
||||
.title(" Command (use {} for selected line) ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(if state.focus == CustomFocus::Input {
|
||||
Style::default().fg(Color::Yellow)
|
||||
} else {
|
||||
Style::default().fg(Color::DarkGray)
|
||||
}),
|
||||
)
|
||||
.wrap(Wrap { trim: true });
|
||||
f.render_widget(input, chunks[1]);
|
||||
|
||||
let pre_command = Paragraph::new(state.pre_command.as_str())
|
||||
.block(
|
||||
Block::default()
|
||||
.title(" Pre-command ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(if state.focus == CustomFocus::PreCommand {
|
||||
Style::default().fg(Color::Yellow)
|
||||
} else {
|
||||
Style::default().fg(Color::DarkGray)
|
||||
}),
|
||||
)
|
||||
.wrap(Wrap { trim: true });
|
||||
f.render_widget(pre_command, chunks[2]);
|
||||
|
||||
let help = "↑/↓: move | Space: toggle | a: select all | Tab: focus | Enter: run | Esc: back | scroll: move";
|
||||
let text = match &app.message {
|
||||
Some(msg) => Text::from(msg.as_str()),
|
||||
None => Text::from(help),
|
||||
};
|
||||
let paragraph = Paragraph::new(text).style(Style::default().fg(Color::Gray));
|
||||
f.render_widget(paragraph, chunks[3]);
|
||||
}
|
||||
|
||||
fn draw_search(f: &mut Frame, app: &mut App) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(5),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.split(f.area());
|
||||
|
||||
let Some(state) = app.search_state.as_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let input = Paragraph::new(state.query.as_str())
|
||||
.block(
|
||||
Block::default()
|
||||
.title(" Search ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Yellow)),
|
||||
)
|
||||
.wrap(Wrap { trim: true });
|
||||
f.render_widget(input, chunks[0]);
|
||||
|
||||
let items: Vec<ListItem> = state
|
||||
.results
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, result)| {
|
||||
let style = if i == state.cursor {
|
||||
Style::default()
|
||||
.bg(Color::Blue)
|
||||
.fg(Color::Black)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
let label = if result.command.is_empty() {
|
||||
format!("[{}] {} — {}", result.group, result.file, result.section)
|
||||
} else {
|
||||
format!(
|
||||
"[{}] {} — {} — {}",
|
||||
result.group, result.file, result.section, result.command
|
||||
)
|
||||
};
|
||||
ListItem::new(label).style(style)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items).block(
|
||||
Block::default()
|
||||
.title(format!(" Results ({}) ", state.results.len()))
|
||||
.borders(Borders::ALL),
|
||||
);
|
||||
state.list_state.select(Some(state.cursor));
|
||||
f.render_stateful_widget(list, chunks[1], &mut state.list_state);
|
||||
|
||||
let preview_text = state
|
||||
.results
|
||||
.get(state.cursor)
|
||||
.map(|r| Text::from(r.command.as_str()))
|
||||
.unwrap_or_else(|| Text::from("No result selected."));
|
||||
let preview = Paragraph::new(preview_text)
|
||||
.block(Block::default().title(" Preview ").borders(Borders::ALL))
|
||||
.wrap(Wrap { trim: true });
|
||||
f.render_widget(preview, chunks[2]);
|
||||
}
|
||||
|
||||
fn draw_groups(f: &mut Frame, app: &mut App, area: ratatui::layout::Rect) {
|
||||
fn draw_groups(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
||||
let items: Vec<ListItem> = app
|
||||
.groups
|
||||
.iter()
|
||||
|
|
@ -223,16 +54,15 @@ fn draw_groups(f: &mut Frame, app: &mut App, area: ratatui::layout::Rect) {
|
|||
.collect();
|
||||
|
||||
let block = Block::default()
|
||||
.title(" Groups ")
|
||||
.title(" Skupiny ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(border_style(app.focus == Focus::Groups));
|
||||
|
||||
let list = List::new(items).block(block);
|
||||
app.group_list_state.select(Some(app.group_index));
|
||||
f.render_stateful_widget(list, area, &mut app.group_list_state);
|
||||
f.render_widget(list, area);
|
||||
}
|
||||
|
||||
fn draw_files(f: &mut Frame, app: &mut App, area: ratatui::layout::Rect) {
|
||||
fn draw_files(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
||||
let items: Vec<ListItem> = app
|
||||
.current_files()
|
||||
.iter()
|
||||
|
|
@ -251,23 +81,22 @@ fn draw_files(f: &mut Frame, app: &mut App, area: ratatui::layout::Rect) {
|
|||
.collect();
|
||||
|
||||
let block = Block::default()
|
||||
.title(" Files ")
|
||||
.title(" Soubory ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(border_style(app.focus == Focus::Files));
|
||||
|
||||
let list = List::new(items).block(block);
|
||||
app.file_list_state.select(Some(app.file_index));
|
||||
f.render_stateful_widget(list, area, &mut app.file_list_state);
|
||||
f.render_widget(list, area);
|
||||
}
|
||||
|
||||
fn draw_sections(f: &mut Frame, app: &mut App, area: ratatui::layout::Rect) {
|
||||
fn draw_sections(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
||||
let items: Vec<ListItem> = app
|
||||
.current_sections()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, section)| {
|
||||
let label = if section.is_run_all() {
|
||||
format!("{} (all)", section.title)
|
||||
format!("{} (vše)", section.title)
|
||||
} else {
|
||||
section.title.clone()
|
||||
};
|
||||
|
|
@ -284,20 +113,19 @@ fn draw_sections(f: &mut Frame, app: &mut App, area: ratatui::layout::Rect) {
|
|||
.collect();
|
||||
|
||||
let block = Block::default()
|
||||
.title(" Commands ")
|
||||
.title(" Příkazy ")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(border_style(app.focus == Focus::Sections));
|
||||
|
||||
let list = List::new(items).block(block);
|
||||
app.section_list_state.select(Some(app.section_index));
|
||||
f.render_stateful_widget(list, area, &mut app.section_list_state);
|
||||
f.render_widget(list, area);
|
||||
}
|
||||
|
||||
fn draw_preview(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
||||
let text = match app.current_section() {
|
||||
Some(section) => {
|
||||
let title = if section.is_run_all() {
|
||||
format!("{} — runs all commands in this file", section.title)
|
||||
format!("{} — spustí všechny příkazy v souboru", section.title)
|
||||
} else {
|
||||
section.title.clone()
|
||||
};
|
||||
|
|
@ -333,11 +161,11 @@ fn draw_preview(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
|||
|
||||
Text::from(lines)
|
||||
}
|
||||
None => Text::from("No command to display."),
|
||||
None => Text::from("Žádný příkaz k zobrazení."),
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.title(" Preview ")
|
||||
.title(" Náhled ")
|
||||
.borders(Borders::ALL);
|
||||
|
||||
let paragraph = Paragraph::new(text).block(block).wrap(Wrap { trim: true });
|
||||
|
|
@ -345,7 +173,7 @@ fn draw_preview(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
|||
}
|
||||
|
||||
fn draw_status(f: &mut Frame, app: &App, area: ratatui::layout::Rect) {
|
||||
let help = "↑/↓: move | →/←: panel | Enter: run | /: search | o: new window | c: custom | e: edit | r: reload | q: quit";
|
||||
let help = "↑/↓ nebo j/k: pohyb | →/←: panel | Enter: spustit | e: editovat | r: reload | q: konec";
|
||||
let text = match &app.message {
|
||||
Some(msg) => Text::from(msg.as_str()),
|
||||
None => Text::from(help),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ use std::path::PathBuf;
|
|||
#[test]
|
||||
fn test_example_files_exist() {
|
||||
let examples = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples");
|
||||
assert!(examples.join("Servers/web.md").exists());
|
||||
assert!(examples.join("Synology/dsmview.md").exists());
|
||||
assert!(examples.join("Scripts/update.md").exists());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue