From 45211dee1b7f9f4462c1ffc6f8e3ceac0c1d0e46 Mon Sep 17 00:00:00 2001 From: ys Date: Sat, 21 Dec 2024 00:25:15 +0000 Subject: [PATCH] add bash scripts --- code/misc/bash/mounts/remote_mounts.sh | 5 +++ code/misc/bash/nnn/cdonquit.sh | 33 ++++++++++++++++++ code/misc/bash/nnn/ewrap.sh | 11 ++++++ code/misc/bash/nnn/nnn-preview.sh | 39 ++++++++++++++++++++++ code/misc/bash/nnn/nnnconfig.sh | 14 ++++++++ code/misc/bash/nnn/preview_cmd.sh | 46 ++++++++++++++++++++++++++ code/misc/bash/nnn/selected | 1 + code/misc/bash/scrcpy/launch_scrcpy.sh | 3 ++ code/misc/bash/ys_onstart_services.sh | 8 +++++ 9 files changed, 160 insertions(+) create mode 100644 code/misc/bash/mounts/remote_mounts.sh create mode 100644 code/misc/bash/nnn/cdonquit.sh create mode 100644 code/misc/bash/nnn/ewrap.sh create mode 100644 code/misc/bash/nnn/nnn-preview.sh create mode 100644 code/misc/bash/nnn/nnnconfig.sh create mode 100644 code/misc/bash/nnn/preview_cmd.sh create mode 100644 code/misc/bash/nnn/selected create mode 100644 code/misc/bash/scrcpy/launch_scrcpy.sh create mode 100644 code/misc/bash/ys_onstart_services.sh diff --git a/code/misc/bash/mounts/remote_mounts.sh b/code/misc/bash/mounts/remote_mounts.sh new file mode 100644 index 0000000..b73ac9f --- /dev/null +++ b/code/misc/bash/mounts/remote_mounts.sh @@ -0,0 +1,5 @@ +#!/bin/bash +#sshfs -o allow_other,default_permissions ys@192.168.0.102:/home/ys /home/ys/ltop_mount/ +sshfs -o allow_other,auto_unmount parents@192.168.0.103:/home/parents /home/ys/mltop_mount/parents +sshfs -o allow_other,auto_unmount mirijs@192.168.0.103:/home/mirijs /home/ys/mltop_mount/miri + diff --git a/code/misc/bash/nnn/cdonquit.sh b/code/misc/bash/nnn/cdonquit.sh new file mode 100644 index 0000000..b3b02d2 --- /dev/null +++ b/code/misc/bash/nnn/cdonquit.sh @@ -0,0 +1,33 @@ + +function n () +{ + # Block nesting of nnn in subshells + [ "${NNNLVL:-0}" -eq 0 ] || { + echo "nnn is already running" + return + } + + # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) + # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to + # see. To cd on quit only on ^G, remove the "export" and make sure not to + # use a custom path, i.e. set NNN_TMPFILE *exactly* as follows: + # NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" + export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" + + # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn + # stty start undef + # stty stop undef + # stty lwrap undef + # stty lnext undef + + # The command builtin allows one to alias nnn to n, if desired, without + # making an infinitely recursive alias + command nnn "$@" + + [ ! -f "$NNN_TMPFILE" ] || { + . "$NNN_TMPFILE" + rm -f "$NNN_TMPFILE" > /dev/null + } +} + + diff --git a/code/misc/bash/nnn/ewrap.sh b/code/misc/bash/nnn/ewrap.sh new file mode 100644 index 0000000..542c561 --- /dev/null +++ b/code/misc/bash/nnn/ewrap.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +if [ -n "$TMUX" ] ; then + # tmux session running + tmux split-window -h "nano \"$*\"" +else + # Remove option --tab for new window + #xfce4-terminal --tab -e "vim \"$*\"" + tmux split-window -h "vim \"$*\"" + #gnome-terminal --tab -e "vim \"$*\"" +fi diff --git a/code/misc/bash/nnn/nnn-preview.sh b/code/misc/bash/nnn/nnn-preview.sh new file mode 100644 index 0000000..f121a81 --- /dev/null +++ b/code/misc/bash/nnn/nnn-preview.sh @@ -0,0 +1,39 @@ +nnn-preview () +{ + # Block nesting of nnn in subshells + if [ -n "$NNNLVL" ] && [ "${NNNLVL:-0}" -ge 1 ]; then + echo "nnn is already running" + return + fi + + # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set) + # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to see. + # To cd on quit only on ^G, remove the "export" and set NNN_TMPFILE *exactly* as this: + # NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" + export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" + + # This will create a fifo where all nnn selections will be written to + NNN_FIFO="$(mktemp --suffix=-nnn -u)" + export NNN_FIFO + (umask 077; mkfifo "$NNN_FIFO") + + # Preview command + preview_cmd="/media/dl92/mydata/projects/code/Bash/nnn/preview_cmd.sh" + + # Use `tmux` split as preview + if [ -e "${TMUX%%,*}" ]; then + tmux split-window -e "NNN_FIFO=$NNN_FIFO" -dh "$preview_cmd" + + # Use `xterm` as a preview window + elif (which xterm &> /dev/null); then + xterm -e "$preview_cmd" & + + # Unable to find a program to use as a preview window + else + echo "unable to open preview, please install tmux or xterm" + fi + + nnn "$@" + + rm -f "$NNN_FIFO" +} diff --git a/code/misc/bash/nnn/nnnconfig.sh b/code/misc/bash/nnn/nnnconfig.sh new file mode 100644 index 0000000..bbc5d54 --- /dev/null +++ b/code/misc/bash/nnn/nnnconfig.sh @@ -0,0 +1,14 @@ + + +source /home/ys/Data/projects/code/Bash/nnn/cdonquit.sh +alias n='n -de' +#export PATH="$HOME/Data/projects/devtools/git/nnn:$HOME/.local/bin:$PATH" +export NNN_PLUG='p:preview-tui' +#export TERM=xterm-256color +export NNN_FIFO=/tmp/nnn.fifo +export EDITOR='sudo nano' +export VISUAL='sudo nano' +#export NNN_TMPFILE="/tmp/nnn" +#"$HOME/.config/nnn/.lastd" + +#export NNN_ICONLOOKUP= 1 diff --git a/code/misc/bash/nnn/preview_cmd.sh b/code/misc/bash/nnn/preview_cmd.sh new file mode 100644 index 0000000..8520a9f --- /dev/null +++ b/code/misc/bash/nnn/preview_cmd.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env sh +# ############################################################################# +# File: preview_cmd.sh +# Description: Minimal example to preview files and directories +# No external dependencies +# Can be easily extended +# Automatically exits when the NNN_FIFO closes +# Prints a `tree` if directory or `head` if it's a file +# +# Shell: POSIX compliant +# Author: Todd Yamakawa +# +# ToDo: +# 1. Add support for more types of files +# e.g. binary files, we shouldn't try to `head` those +# ############################################################################# + +# Check FIFO +NNN_FIFO=${NNN_FIFO:-$1} +if [ ! -r "$NNN_FIFO" ]; then + echo "Unable to open \$NNN_FIFO='$NNN_FIFO'" | less + exit 2 +fi + +# Read selection from $NNN_FIFO +while read -r selection; do + clear + lines=$(($(tput lines)-1)) + cols=$(tput cols) + + # Print directory tree + if [ -d "$selection" ]; then + cd "$selection" || continue + tree | head -n $lines | cut -c 1-"$cols" + continue + fi + + # Print file head + if [ -f "$selection" ]; then + head -n $lines "$selection" | cut -c 1-"$cols" + continue + fi + + # Something went wrong + echo "Unknown type: '$selection'" +done < "$NNN_FIFO" diff --git a/code/misc/bash/nnn/selected b/code/misc/bash/nnn/selected new file mode 100644 index 0000000..fa3a928 --- /dev/null +++ b/code/misc/bash/nnn/selected @@ -0,0 +1 @@ +nnnconfig.sh diff --git a/code/misc/bash/scrcpy/launch_scrcpy.sh b/code/misc/bash/scrcpy/launch_scrcpy.sh new file mode 100644 index 0000000..d9fe71a --- /dev/null +++ b/code/misc/bash/scrcpy/launch_scrcpy.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +scrcpy --turn-screen-off --disable-screensaver --show-touches --stay-awake --video-codec=h265 --video-bit-rate=16M --audio-bit-rate=256K --max-fps=144 --max-size=2160 diff --git a/code/misc/bash/ys_onstart_services.sh b/code/misc/bash/ys_onstart_services.sh new file mode 100644 index 0000000..b2adebe --- /dev/null +++ b/code/misc/bash/ys_onstart_services.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd /home/ys/Data/projects/llm/OpenWebUI +open-webui serve --port 8085 & + + + +