Add plugin to split or join files

This commit is contained in:
Arun Prakash Jana 2019-06-06 23:27:57 +05:30
parent 40afe7ca4d
commit a96ad1dab0
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 36 additions and 0 deletions

View file

@ -17,6 +17,7 @@
| pdfview | sh | pdftotext/mupdf-tools | View current PDF file in `$PAGER` | | pdfview | sh | pdftotext/mupdf-tools | View current PDF file in `$PAGER` |
| picker | sh | nnn | Pick files and pipe the newline-separated list to another utility | | picker | sh | nnn | Pick files and pipe the newline-separated list to another utility |
| pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme | | pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme |
| splitjoin | bash | split, cat | Split current file or join selection |
| sxiv | sh | sxiv | Browse images in a dir in sxiv, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))| | sxiv | sh | sxiv | Browse images in a dir in sxiv, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))|
| transfer | sh | curl | Upload current file to transfer.sh | | transfer | sh | curl | Upload current file to transfer.sh |
| upgrade | sh | wget | Upgrade to latest nnn version manually on Debian 9 Stretch | | upgrade | sh | wget | Upgrade to latest nnn version manually on Debian 9 Stretch |

35
plugins/splitjoin Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Description: Splits the file passed as argument or joins selection
#
# Note: Adds numeric suffix to split files
# Adds '.join' suffix to the first file to be joined and saves as output file for join
#
# Shell: Bash
# Author: Arun Prakash Jana
selection=~/.config/nnn/.selection
echo -n "press 's' (split current file) or 'j' (join selection): "
read resp
if [ "$resp" = "j" ]; then
if [ -s "$selection" ]; then
arr=$(cat $selection | tr '\0' '\n')
{ read -r file; } <<< "$arr"
file=$(basename "$file").out
cat "$selection" | sort -z | xargs -0 -i cat {} > "$file"
fi
elif [ "$resp" = "s" ]; then
if ! [ -z "$1" ] && [ -f "$1" ] ; then
# a single file is passed
echo -n "split size in MB: "
read size
if ! [ -z "$size" ]; then
split -d -b "$size"M "$1" "$1"
fi
fi
fi