aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tmux
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-10-18 18:40:04 -0500
committerToby Vincent <tobyv13@gmail.com>2022-10-18 18:40:04 -0500
commita69bbedfd1f3e5c0eb53aed980de65e4ec6b4d70 (patch)
tree65b93424c4053f0defc2f26e3cd2806d97e29dbf /tmux
parent5bdf3c640f390305fef7f771ea7f05db85482ff6 (diff)
feat(sh): add lessfilter script for previewing projects
Diffstat (limited to 'tmux')
-rwxr-xr-xtmux/.local/bin/previewer.sh114
-rwxr-xr-xtmux/.local/bin/tmux-sessionizer9
2 files changed, 5 insertions, 118 deletions
diff --git a/tmux/.local/bin/previewer.sh b/tmux/.local/bin/previewer.sh
deleted file mode 100755
index d064a09..0000000
--- a/tmux/.local/bin/previewer.sh
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/sh
-# shellcheck disable=2046
-
-SCRIPT="$(basename "$0")"
-
-long='remote,verbose,help'
-short='rvh'
-
-if ! opts="$(getopt -o $short -l $long -n "$SCRIPT" -- "$@")"; then
- exit 1
-fi
-
-eval set -- "$opts"
-
-help() {
- cat <<-EOF
- $SCRIPT
- Toby Vincent <tobyv13@gmail.com>
-
- $SCRIPT
- Shows preview of a directory. Designed to be used with fzf's '--preview'.
-
- USAGE:
- $SCRIPT [OPTION ...] <PATH> [PATH ...]
-
- OPTIONS:
- -r, --remote Treat path as a remote repository
- -v, --verbose Increase verbosity
- -h, --help Show this help
- EOF
-}
-
-say() {
- printf "%s: %s\n" "$SCRIPT" "$@"
-}
-
-say_verbose() {
- if [ "$verbose" -gt "0" ]; then
- say "$@"
- fi
-}
-
-say_err() {
- say "$@" >&2
-}
-
-err() {
- err_dir="$1"
- shift
- say_err "cannot preview '$err_dir': $*"
- exit 1
-}
-
-err_help() {
- help
- err "$*"
-}
-
-verbose=0
-remote=false
-width=$(((($(tput cols) * 3) + (4 - 1)) / 4))
-while true; do
- case "$1" in
- -h | --help)
- help
- exit 0
- ;;
- -v | --verbose)
- verbose=$((verbose + 1))
- shift
- ;;
- -r | --remote)
- remote=true
- shift
- ;;
- -w | --width)
- width=$2
- shift 2
- ;;
- --)
- shift
- break
- ;;
- *)
- err_help "Invalid argument: $1"
- ;;
- esac
-done
-
-show_logo="always"
-if [ "$width" -lt 80 ]; then
- show_logo="never"
-fi
-
-if [ "$#" -eq 0 ]; then
- IFS='
-'
- set -o noglob
- set -- $(cat)
-fi
-
-while [ $# -gt 0 ]; do
- if $remote; then
- hut git show --repo "$1" 2>/dev/null ||
- gh repo view "$1" 2>/dev/null ||
- err "$1" "Failed to find remote repository"
- else
- onefetch --hidden --show-logo="$show_logo" "$1" 2>/dev/null ||
- ([ -e "$1"/README.md ] && glow --local --style=dark "$1"/README.md) 2>/dev/null ||
- exa --tree --git-ignore --level=3 --icons "$1" 2>/dev/null ||
- err "$1" "Failed to preview directory"
- fi
- shift
-done
diff --git a/tmux/.local/bin/tmux-sessionizer b/tmux/.local/bin/tmux-sessionizer
index 04f8633..a440068 100755
--- a/tmux/.local/bin/tmux-sessionizer
+++ b/tmux/.local/bin/tmux-sessionizer
@@ -2,19 +2,20 @@
# shellcheck disable=2016,2089
PROJECT_DIR="$HOME/src"
+DOCKER_DIR="$HOME/dkr"
SESSION_DIR="$XDG_DATA_HOME/nvim/sessions"
-PREVIEW_CMD="previewer.sh {} 2>/dev/null || previewer.sh {q} --remote"
-ATTACHED="$(tmux list-sessions -F '#{?session_attached,#{session_path},}' 2>/dev/null | sed '/^$/d')"
+PREVIEW_CMD="([ -n {} ] && less {}) || ([ ! -e {q} ] && less {q})"
+ATTACHED="$(tmux display -p '#{session_path}')"
if [ "$#" -eq 0 ]; then
# shellcheck disable=2046
set -- $({
printf %s\\n "$HOME/.dotfiles"
- fd . "$PROJECT_DIR" --type=d --max-depth=1
+ fd . "$PROJECT_DIR" "$DOCKER_DIR" --type=d --max-depth=1
fd . "$SESSION_DIR" --type=f --max-depth=1 | sed "s|^$SESSION_DIR/||" | sed 's#%%\|__#/#g'
} | 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 -- --multi --print-query -d/ --with-nth -1 --preview-window=right,75% --preview="$PREVIEW_CMD" |
+ fzf-tmux -p -- --multi --print-query -d/ --with-nth -1 --preview-window='right,75%,<30(up,30%,border-bottom)' --preview="$PREVIEW_CMD" |
tr -s '\n' ' ')
fi