3 # Description: Splits the file passed as argument or joins selection
5 # Note: Adds numeric suffix to split files
6 # Adds '.out suffix to the first file to be joined and saves as output file for join
8 # Shell: POSIX compliant
9 # Authors: Arun Prakash Jana, ath3
11 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
14 if [ -s "$selection" ]; then
15 printf "press 's' (split current file) or 'j' (join selection): "
19 if [ "$resp" = "j" ]; then
20 if [ -s "$selection" ]; then
21 arr=$(tr '\0' '\n' < "$selection")
22 if [ "$(echo "$arr" | wc -l)" -lt 2 ]; then
23 echo "joining needs at least 2 files"
28 if [ -d "$entry" ]; then
29 echo "can't join directories"
34 file="$(basename "$(echo "$arr" | sed -n '1p' | sed -e 's/[0-9][0-9]$//')")"
35 sort -z < "$selection" | xargs -0 -I{} cat {} > "${file}.out"
38 if [ -p "$NNN_PIPE" ]; then
39 printf "-" > "$NNN_PIPE"
42 elif [ "$resp" = "s" ]; then
43 if [ -n "$1" ] && [ -f "$1" ]; then
44 # a single file is passed
45 printf "split size in MB: "
48 if [ -n "$size" ]; then
49 split -d -b "$size"M "$1" "$1"