Created
November 26, 2024 13:38
-
-
Save wbob/5a1267af6af38586f4fa9b07afb9657b to your computer and use it in GitHub Desktop.
sqlite wrapper to get less PAGER support in a split window tmux pane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# simple sqlite-wrapper to have PAGER support | |
# | |
# install and chmod+x to ~/bin/wsqlite and load in ~/.profile PATH | |
set -eE | |
command -v sqlite3 >/dev/null || echo "sqlite3 not found, please install" || exit 1 | |
command -v tmux >/dev/null || echo "tmux not found, please install" || exit 1 | |
usage() { | |
echo "usage: wsqlite <sqlite.db>" | |
} | |
test -z $1 && usage && exit 0 | |
target="$1" | |
fullpath=$(readlink -f .) | |
fifo="$fullpath/sqlitepager.tmp" | |
rc="$fullpath/sqlitepager.rc" | |
test -p "$fifo" && rm -v "$fifo" | |
mkfifo "$fifo" | |
test -f "$rc" && rm -v "$rc" | |
echo ".output \"$fifo\"" > "$rc" | |
echo ".mode column" >> "$rc" | |
cat "$rc" | |
tmux kill-session -t "sqlite" >/dev/null || continue | |
tmux new-session -s "sqlite" -d | |
tmux split-window -d -v -t "sqlite" | |
tmux send -t "sqlite.0" "sqlite3 -init \"$rc\" \"$target\"" ENTER | |
tmux send -t "sqlite.1" "less -f -S \"$fifo\"" ENTER | |
tmux attach-session -d -t "sqlite.0" -c "ls" | |
rm "$fifo" | |
rm "$rc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment