diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-10-19 19:13:29 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-10-19 19:13:29 -0500 |
commit | de64870b97417e6ae22420de55cabd203cd710d0 (patch) | |
tree | f3c5e8fc65bcd6bd35e5e4e7a8170c6411f5b609 | |
parent | d40af8b9b7eaeebd699f867906d8817236732984 (diff) |
refactor(tmux): clean up tmux-sessionizer repo stuff
-rw-r--r-- | sh/.profile | 4 | ||||
-rwxr-xr-x | tmux/.local/bin/tmux-sessionizer | 26 |
2 files changed, 17 insertions, 13 deletions
diff --git a/sh/.profile b/sh/.profile index 47a62ad..46ef47e 100644 --- a/sh/.profile +++ b/sh/.profile @@ -30,8 +30,9 @@ export PASSWORD_STORE_DIR="$HOME/.password-store" export PASSWORD_STORE_ENABLE_EXTENSIONS=true export ZK_NOTEBOOK_DIR="$HOME/notebook" export STARSHIP_LOG="error" -export FZF_DEFAULT_COMMAND="fd --type f || git ls-tree -r --name-only HEAD || rg --files || find ." export FZF_TMUX_OPTS="-p" +export FZF_PREVIEW_COMMAND='less {} 2>/dev/null' +export FZF_DEFAULT_COMMAND="fd --type f || git ls-tree -r --name-only HEAD || rg --files || find ." export FZF_DEFAULT_OPTS='--bind ctrl-q:abort --bind ctrl-y:preview-up --bind ctrl-e:preview-down @@ -43,7 +44,6 @@ export FZF_DEFAULT_OPTS='--bind ctrl-q:abort --bind alt-down:half-page-down --color fg:#ebdbb2,hl:#fabd2f,fg+:#ebdbb2,hl+:#fabd2f --color info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#665c54' -export FZF_PREVIEW_COMMAND='bat --style=numbers,changes --wrap never --color always {} 2>/dev/null' export PATH="$PATH:$HOME/.local/bin" diff --git a/tmux/.local/bin/tmux-sessionizer b/tmux/.local/bin/tmux-sessionizer index 7b38dc1..8cf2658 100755 --- a/tmux/.local/bin/tmux-sessionizer +++ b/tmux/.local/bin/tmux-sessionizer @@ -5,7 +5,7 @@ if [ "$#" -eq 0 ]; then PROJECT_DIR="$HOME/src" DOCKER_DIR="$HOME/dkr" SESSION_DIR="$XDG_DATA_HOME/nvim/sessions" - PREVIEW_CMD="([ -n {} ] && less {}) || ([ ! -e {q} ] && less {q})" + PREVIEW_CMD='sel={}; less ${sel:-{q}} 2>/dev/null' ATTACHED=$(tmux display -p '#{session_path}') lines=$(tmux display -p "#{pane_height}") @@ -21,22 +21,26 @@ if [ "$#" -eq 0 ]; then } | sed 's|/$||' | sed "\|^$HOME\$|d" | sed "\|^$ATTACHED\$|d" | sort -u | timestamp.sh --git --sessions="$SESSION_DIR" --format="{}:{1}" | sort -r | cut -d':' -f2 | fzf-tmux -p "$WIDTH,$HEIGHT" -- --multi --print-query -d/ --with-nth -1 --preview-window='right,75%,<80(up,75%,border-bottom)' --preview="$PREVIEW_CMD" | - tr -s '\n' ' ') + tr -s '\n' ' ') && [ $# -gt 1 ] && shift fi while [ $# -gt 0 ]; do session_path="$1" shift + if [ ! -d "$session_path" ]; then - repo=$(printf %s "$session_path" | sed 's/.git$//' | sed 's|/$||') - remotes="$repo https://git.sr.ht/$repo https://github.com/$repo" - for remote in $remotes; do - if timeout 3s git ls-remote "$remote" CHECK_GIT_REMOTE_URL_REACHABILITY; then - session_path="$HOME/src/$(basename "$remote")" - git clone "$remote" "$session_path" - break - fi - done + repo="$session_path" + if [ "$repo" = "${repo%/*}/${repo#*/}" ]; then + for remote in ${GIT_REMOTES:-https://git.sr.ht https://github.com}; do + if git ls-remote "$remote/$repo" CHECK_GIT_REMOTE_REACHABILITY; then + session_path="$remote/$repo" + break + fi + done + fi + + session_path="$HOME/src/$(basename "$session_path")" + git clone "$repo" "$session_path" fi if [ ! -d "$session_path" ]; then |