dotfiles/dot_tmux/plugins/tmux-copycat/scripts/executable_copycat_git_special.sh

57 lines
1.2 KiB
Bash
Raw Normal View History

2023-11-13 13:48:17 +01:00
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PANE_CURRENT_PATH="$1"
source "$CURRENT_DIR/helpers.sh"
git_status_files() {
git -C "$PANE_CURRENT_PATH" status -s
}
formatted_git_status() {
local raw_gist_status="$(git_status_files)"
echo "$raw_gist_status" | cut -c 4-
}
exit_if_no_results() {
local results="$1"
if [ -z "$results" ]; then
display_message "No results!"
exit 0
fi
}
concatenate_files() {
local git_status_files="$(formatted_git_status)"
exit_if_no_results "$git_status_files"
local result=""
# Undefined until later within a while loop.
local file_separator
while read -r line; do
result="${result}${file_separator}${line}"
file_separator="|"
done <<< "$git_status_files"
echo "$result"
}
# Creates one, big regex out of git status files.
# Example:
# `git status` shows files `foo.txt` and `bar.txt`
# output regex will be:
# `(foo.txt|bar.txt)
git_status_files_regex() {
local concatenated_files="$(concatenate_files)"
local regex_result="(${concatenated_files})"
echo "$regex_result"
}
main() {
local search_regex="$(git_status_files_regex)"
# starts copycat mode
$CURRENT_DIR/copycat_mode_start.sh "$search_regex"
}
main