summaryrefslogtreecommitdiff
path: root/ar/.local/bin/tmuxopen
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-06-21 03:33:46 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-06-21 03:33:46 +0900
commit8d7892fa0e586026f75d2024fb74fb8f3c58464e (patch)
treebc9098ae01f49a7659efeecff0cb0ee0f33d117b /ar/.local/bin/tmuxopen
parentbf4e657b53d3ee2d6e55edebc57a040e18e48806 (diff)
modified bin/tmuxopen
Diffstat (limited to 'ar/.local/bin/tmuxopen')
-rwxr-xr-xar/.local/bin/tmuxopen84
1 files changed, 44 insertions, 40 deletions
diff --git a/ar/.local/bin/tmuxopen b/ar/.local/bin/tmuxopen
index 1dce717..a66fb96 100755
--- a/ar/.local/bin/tmuxopen
+++ b/ar/.local/bin/tmuxopen
@@ -7,7 +7,6 @@ usage() {
echo ""
echo "Options:"
echo " -h, --help : Show this help message"
- echo " -d, --debug : Enable debug output"
echo ""
echo "Controls:"
echo " Tab Select files"
@@ -20,16 +19,45 @@ usage() {
echo ""
echo "Example:"
echo " tmuxopen # Run the normal search and open"
- echo " tmuxopen --debug # Run with debug output"
-}
-
-debug() {
- [ "$DEBUG" -eq 1 ] && echo "DEBUG: $*" >&2
}
get_fzf_output() {
- RG_BIND="ctrl-g:reload:rg --line-number --follow --no-heading --color=always --smart-case --glob '!**/.git/**' --glob '!node_modules/**' '' 2>/dev/null || true"
- FILE_BIND="ctrl-f:reload:rg --follow --files --glob '!**/.git/**' --glob '!node_modules/**' 2>/dev/null || true"
+ # Create temporary files to store search state
+ tmp_files="/tmp/gif-files-$$"
+ tmp_content_query="/tmp/gif-content_query-$$"
+
+ # Cleanup on exit
+ trap "rm -f $tmp_files $tmp_content_query" EXIT
+
+ RG_FIXED_BIND="ctrl-g:transform-query(
+ echo {q} > $tmp_content_query;
+ echo {q}
+ )+reload(
+ rm -f $tmp_files;
+ rg --line-number --follow --fixed-strings --hidden --no-heading --color=always --smart-case --glob '!**/.git/**' --glob '!node_modules/**' {q} 2>/dev/null || true
+ )"
+ FILE_BIND="ctrl-f:transform-query(
+ current_query={q};
+ if [ ! -s $tmp_content_query ]; then
+ echo \$current_query > $tmp_content_query;
+ fi;
+ rg --hidden --follow --files-with-matches --no-messages --glob '!**/.git/**' --glob '!node_modules/**' -- \$current_query > $tmp_files;
+ echo
+ )+reload(
+ if [ -s $tmp_files ]; then
+ if [ -n {q} ]; then
+ grep -i -- {q} $tmp_files || true;
+ else
+ cat $tmp_files;
+ fi | while IFS= read -r file; do
+ if [ -f \"\$file\" ]; then
+ echo \"\$file:1\";
+ fi;
+ done;
+ else
+ rg --follow --files --glob '!**/.git/**' --glob '!node_modules/**' 2>/dev/null;
+ fi
+ )"
if command -v fd >/dev/null 2>&1; then
DIR_BIND="ctrl-d:change-prompt(directory> )+reload(cd \"$HOME\" && echo \"$HOME\"; fd --follow --type d --hidden --absolute-path --color never --exclude .git --exclude node_modules)"
else
@@ -41,10 +69,10 @@ get_fzf_output() {
--ansi --multi --delimiter : \
--reverse \
--print-query \
- --preview 'bat --style=numbers --color=always --highlight-line {2} {1} 2>/dev/null || echo "Preview not available"' \
- --preview-window 'right,45%,border-bottom,+{2}+3/3,~3' \
+ --preview 'bat --style=numbers --color=always --highlight-line {2} {1} 2>/dev/null || bat --color=always {} 2>/dev/null || ls -la {} 2>/dev/null || echo "Preview is not available."' \
+ --preview-window 'right,55%,border-bottom,+{2}+3/3,~3' \
--bind "$FILE_BIND" \
- --bind "$RG_BIND" \
+ --bind "$RG_FIXED_BIND" \
--bind "$DIR_BIND" \
--bind 'ctrl-c:abort' \
--header "^f filenames, ^g contents, ^d directories"
@@ -67,20 +95,12 @@ open_files_in_nvim() {
nvim_cmd="$nvim_cmd +$line $file"
done
nvim_cmd="$nvim_cmd -c 'let @/=\"$NVIM_SEARCH_REGISTRY\"'"
- debug "Running command in pane $pane: $nvim_cmd"
tmux send-keys -t "$pane" "$nvim_cmd" C-m
}
-# Main logic
-DEBUG=0
-
# Parse command line arguments
while [ "$#" -gt 0 ]; do
case "$1" in
- -d | --debug)
- DEBUG=1
- shift
- ;;
-h | --help)
usage
exit 0
@@ -106,18 +126,13 @@ if [ -z "$TMUX" ]; then
fi
raw_output=$(get_fzf_output)
-debug "Raw fzf output:"
-debug "$raw_output"
set_nvim_search_variable "$raw_output"
# Split the newline-delimited output into an array, skipping the first line (query)
selections=$(echo "$raw_output" | sed 1d)
-debug "Number of selections: $(echo "$selections" | wc -l)"
-debug "Selections:"
-debug "$selections"
if [ -z "$selections" ]; then
- debug "No selections made"
+ echo "No selections made"
exit 0
fi
@@ -127,46 +142,38 @@ count=0
# Use a here document to avoid subshell issues
while IFS= read -r selection; do
+ echo "$selection"
file=$(echo "$selection" | awk -F: '{print $1}')
line=$(echo "$selection" | awk -F: '{print $2}')
- debug "Processing selection: $selection"
- debug "File: $file, Line: $line"
if [ -f "$file" ]; then
files="$files $file"
lines="$lines $line"
count=$((count + 1))
else
- debug "File not found: $file"
+ echo "File not found: $file"
fi
done <<EOF
$selections
EOF
-debug "Number of valid files: $count"
-debug "Valid files:"
-debug "$files"
if [ "$count" -eq 0 ]; then
- debug "No valid files selected"
+ echo "No valid files selected"
exit 0
fi
if [ "$count" -eq 1 ]; then
- debug "Opening single file"
open_files_in_nvim "$(tmux display-message -p '#P')" 1
else
- debug "Opening multiple files"
- window_name="TheSiahxyz-$(date +%s)"
+ window_name="$(date +%s)"
tmux new-window -n "$window_name"
case "$count" in
2)
- debug "Opening 2 files side-by-side"
tmux split-window -t "$window_name" -h -p 50
open_files_in_nvim "$window_name.1" 1
open_files_in_nvim "$window_name.2" 2
tmux select-pane -t "$window_name.1"
;;
3)
- debug "Opening 3 files"
tmux split-window -t "$window_name" -h -p 50
tmux split-window -t "$window_name.2" -v -p 50
open_files_in_nvim "$window_name.1" 1
@@ -174,7 +181,6 @@ else
open_files_in_nvim "$window_name.3" 3
;;
*)
- debug "Opening 4 or more files"
tmux split-window -t "$window_name" -h -p 50
tmux split-window -t "$window_name.1" -v -p 50
tmux split-window -t "$window_name.3" -v -p 50
@@ -189,5 +195,3 @@ else
;;
esac
fi
-
-debug "Script completed"