add bash scripts
This commit is contained in:
33
code/misc/bash/nnn/cdonquit.sh
Normal file
33
code/misc/bash/nnn/cdonquit.sh
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
code/misc/bash/nnn/ewrap.sh
Normal file
11
code/misc/bash/nnn/ewrap.sh
Normal file
@@ -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
|
||||
39
code/misc/bash/nnn/nnn-preview.sh
Normal file
39
code/misc/bash/nnn/nnn-preview.sh
Normal file
@@ -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"
|
||||
}
|
||||
14
code/misc/bash/nnn/nnnconfig.sh
Normal file
14
code/misc/bash/nnn/nnnconfig.sh
Normal file
@@ -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
|
||||
46
code/misc/bash/nnn/preview_cmd.sh
Normal file
46
code/misc/bash/nnn/preview_cmd.sh
Normal file
@@ -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"
|
||||
1
code/misc/bash/nnn/selected
Normal file
1
code/misc/bash/nnn/selected
Normal file
@@ -0,0 +1 @@
|
||||
nnnconfig.sh
|
||||
Reference in New Issue
Block a user