mirror of
https://github.com/hydroxycarbamide/dotfiles.git
synced 2025-05-11 15:02:16 -04:00
Add nnn
This commit is contained in:
parent
0ef5de12ac
commit
c0889285ff
58 changed files with 5175 additions and 0 deletions
52
dot_config/nnn/plugins/executable_splitjoin
Normal file
52
dot_config/nnn/plugins/executable_splitjoin
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Description: Splits the file passed as argument or joins selection
|
||||
#
|
||||
# Note: Adds numeric suffix to split files
|
||||
# Adds '.out suffix to the first file to be joined and saves as output file for join
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Authors: Arun Prakash Jana, ath3
|
||||
|
||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||
resp=s
|
||||
|
||||
if [ -s "$selection" ]; then
|
||||
printf "press 's' (split current file) or 'j' (join selection): "
|
||||
read -r resp
|
||||
fi
|
||||
|
||||
if [ "$resp" = "j" ]; then
|
||||
if [ -s "$selection" ]; then
|
||||
arr=$(tr '\0' '\n' < "$selection")
|
||||
if [ "$(echo "$arr" | wc -l)" -lt 2 ]; then
|
||||
echo "joining needs at least 2 files"
|
||||
exit
|
||||
fi
|
||||
for entry in $arr
|
||||
do
|
||||
if [ -d "$entry" ]; then
|
||||
echo "can't join directories"
|
||||
exit
|
||||
fi
|
||||
done
|
||||
|
||||
file="$(basename "$(echo "$arr" | sed -n '1p' | sed -e 's/[0-9][0-9]$//')")"
|
||||
sort -z < "$selection" | xargs -0 -I{} cat {} > "${file}.out"
|
||||
|
||||
# Clear selection
|
||||
if [ -p "$NNN_PIPE" ]; then
|
||||
printf "-" > "$NNN_PIPE"
|
||||
fi
|
||||
fi
|
||||
elif [ "$resp" = "s" ]; then
|
||||
if [ -n "$1" ] && [ -f "$1" ]; then
|
||||
# a single file is passed
|
||||
printf "split size in MB: "
|
||||
read -r size
|
||||
|
||||
if [ -n "$size" ]; then
|
||||
split -d -b "$size"M "$1" "$1"
|
||||
fi
|
||||
fi
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue