Skip to content

Commit 44dc239

Browse files
committed
fix: use direct tty read for ZLE-safe placeholder injection; bump to v0.7.1
1 parent d0be61e commit 44dc239

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.7.1] - 2026-03-31
9+
### Fixed
10+
- Resolved an issue where placeholders ({{variable}}) were injected into the ZLE buffer without user input.
11+
- Switched to a direct TTY read method to ensure interactive prompts work correctly within Zsh widgets.
12+
- Improved trailing whitespace trimming for vault commands.
13+
814
## [0.7.0] - 2026-03-27
915

1016
### Added

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## XC manager
2-
**Version: 0.7.0**
2+
**Version: 0.7.1**
33
[![Asome Zsh Plugins](https://img.shields.io/badge/Awesome-Zsh%20Plugins-brightgreen)](https://github.com/unixorn/awesome-zsh-plugins)
44

55
![XC-Manager TUI](https://github.com/Rakosn1cek/xc-manager/blob/main/preview-2.png)
@@ -13,6 +13,12 @@
1313

1414
A high-performance, minimal dependency Zsh vault for managing complex commands.
1515

16+
## [0.7.1] - 2026-03-31
17+
### Fixed
18+
- Resolved an issue where placeholders ({{variable}}) were injected into the ZLE buffer without user input.
19+
- Switched to a direct TTY read method to ensure interactive prompts work correctly within Zsh widgets.
20+
- Improved trailing whitespace trimming for vault commands.
21+
1622
## What's New in v0.7.0
1723
### Interactive Templating & Sync Engine
1824
The v0.7.0 release transforms XC from a static command vault into a dynamic template engine.

autoload/fzf-vault-widget

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,26 @@ _xc_add_alias() {
1010
local cmd="${1%% -> *}"
1111
local target="$2"
1212
local marker="$3"
13-
1413
[[ ! -f "$target" ]] && touch "$target"
15-
16-
stty sane </dev/tty # canonical mode + echo restored - backspace works, fix in (v0.5.3-beta)
14+
stty sane </dev/tty
1715
printf "\n\e[32mXC-Manager\e[0m Saving to: \e[2m%s\e[0m\n" "$target" > /dev/tty
1816
printf "\e[32mXC-Manager\e[0m Alias Name: " > /dev/tty
1917
read alias_name < /dev/tty
2018
stty -echo < /dev/tty
21-
2219
[[ -z "$alias_name" ]] && return 0
23-
2420
if grep -qE "^alias $alias_name=" "$target"; then
2521
printf "\e[31m[!] Error:\e[0m '%s' already exists in %s\n" "$alias_name" "$target" > /dev/tty
2622
sleep 1; return 1
2723
fi
28-
2924
if type "$alias_name" >/dev/null 2>&1; then
3025
printf "\e[31m[!] Error:\e[0m '%s' is a system command.\n" "$alias_name" > /dev/tty
3126
sleep 1; return 1
3227
fi
33-
3428
if ! grep -qF "$marker" "$target"; then
3529
printf "\n%s\n" "$marker" >> "$target"
3630
fi
37-
3831
echo "alias $alias_name=\"$cmd\"" >> "$target"
3932
alias "$alias_name"="$cmd"
40-
4133
printf "\e[32mSuccess!\e[0m Alias '\e[1m%s\e[0m' is live.\n" "$alias_name" > /dev/tty
4234
sleep 0.5
4335
}
@@ -46,7 +38,6 @@ _xc_add_alias() {
4638
local vault_dir="${XC_VAULT_DIR:-$HOME/.local/share/xc}"
4739
local state_file="$HOME/.cache/xc_active_vault"
4840
local active_name="main"
49-
5041
[[ -f "$state_file" ]] && active_name=$(<"$state_file")
5142
local vault_file="$vault_dir/${active_name}.txt"
5243

@@ -70,27 +61,35 @@ local selected=$(fzf \
7061
--bind "ctrl-r:rebind(alt-d,alt-e)+change-header(Vault: [$active_name] | Alt-E: Alias | Alt-D: Delete | Ctrl-A: Global)+reload(cat \"$vault_file\")" \
7162
< "$vault_file")
7263

73-
if [ -n "$selected" ]; then
64+
# --- 5. Integrated Placeholder Logic ---
65+
if [[ -n "$selected" ]]; then
7466
local cmd="${selected%% -> *}"
7567
local clean_cmd="${cmd%"${cmd##*[![:space:]]}"}"
7668

77-
# --- 5. Integrated Placeholder Logic ---
78-
while [[ "$clean_cmd" == *"{{"*"}}"* ]]; do
79-
# Extract only the text between the first {{ and }}
80-
local var_part="${clean_cmd#*\{\{}"
81-
local var_name="${var_part%%\}\}*}"
82-
local user_input=""
83-
84-
# vared for a clean, interactive prompt
85-
vared -p "Value for {{$var_name}}: " user_input
86-
87-
# Abort if user hits enter without typing or cancels
88-
[[ -z "$user_input" ]] && break
89-
90-
# Replace the placeholder with the input
91-
clean_cmd="${clean_cmd//\{\{$var_name\}\}/$user_input}"
92-
done
69+
# Check for placeholders
70+
if [[ "$clean_cmd" == *"{{"* ]]; then
71+
# Pause ZLE so we can talk to the terminal directly
72+
zle -I
73+
74+
while [[ "$clean_cmd" == *"{{"*"}}"* ]]; do
75+
# Extract the placeholder name
76+
local var_part="${clean_cmd#*\{\{}"
77+
local var_name="${var_part%%\}\}*}"
78+
[[ "$var_part" == "$clean_cmd" ]] && break
79+
80+
# Direct terminal prompt (bypasses ZLE restrictions)
81+
local user_input=""
82+
printf "\e[32mXC-\e[0m Enter value for {{%s}}: " "$var_name" > /dev/tty
83+
84+
# Read from the terminal, not the shell buffer
85+
read user_input < /dev/tty
86+
87+
# Replace the placeholder
88+
clean_cmd="${clean_cmd//\{\{$var_name\}\}/$user_input}"
89+
done
90+
fi
9391

92+
# Inject the final command into the buffer
9493
LBUFFER="$clean_cmd"
9594
fi
9695

autoload/xc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# File: ~/arch-projects/XC-Manager/autoload/xc
88
# ==============================================================================
99

10-
readonly XC_VERSION="0.7.0"
10+
readonly XC_VERSION="0.7.1"
1111
setopt EXTENDED_GLOB
1212

1313
# ==============================================================================

0 commit comments

Comments
 (0)