Skip to content

Instantly share code, notes, and snippets.

@N0rbert
Last active October 26, 2020 22:24
Show Gist options
  • Save N0rbert/b0b11340e588b33fab542b0c72837e41 to your computer and use it in GitHub Desktop.
Save N0rbert/b0b11340e588b33fab542b0c72837e41 to your computer and use it in GitHub Desktop.
Caja-Actions script to compare files or directories by using Meld in Caja, should be placed to `~/.config/caja/scripts`, was found sometime ago on the Deutsch forum
#!/bin/bash
#
# meld script for caja, place it to ~/.config/caja/scripts
#
# Copyright 2014 Norbert ..... <norbert@Entwicklung>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
function ScanSelectedEntries() {
# Scan selected entries in primary pane
let idx=0
PrepArray=$(
echo -e "${CAJA_SCRIPT_SELECTED_FILE_PATHS}" | while read line; do
if [ ${#line} -gt 0 ]; then
echo Files1[$idx]="'$line'"
let idx=$idx+1
fi
done
)
eval "$PrepArray"
let numFiles1=${#Files1[@]}
for((i = 0; i < $numFiles1; i++)); do
Type1[$i]="-"
[ -f "${Files1[$i]}" ] && Type1[$i]="f"
[ -d "${Files1[$i]}" ] && Type1[$i]="d"
[ -h "${Files1[$i]}" ] && Type1[$i]="h"
done
# Scan selected entries in 'next' pane (opened with F3)
let idx=0
PrepArray=$(
echo -e "${CAJA_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS}" | while read line; do
if [ ${#line} -gt 0 ]; then
echo Files2[$idx]="'$line'"\;
let idx=$idx+1
fi
done
)
eval "$PrepArray"
let numFiles2=${#Files2[@]}
for((i = 0; i < $numFiles2; i++)); do
Type2[$i]=""
[ -f "${Files2[$i]}" ] && Type2[$i]="f"
[ -d "${Files2[$i]}" ] && Type2[$i]="d"
[ -h "${Files2[$i]}" ] && Type2[$i]="h"
done
}
function DebugOutput() {
T=/tmp/tmpout
(
echo -e "CAJA_SCRIPT_CURRENT_URI " $CAJA_SCRIPT_CURRENT_URI
echo -e "CAJA_SCRIPT_SELECTED_FILE_PATHS " $CAJA_SCRIPT_SELECTED_FILE_PATHS
echo -e "CAJA_SCRIPT_SELECTED_URIS " $CAJA_SCRIPT_SELECTED_URIS
echo -e "CAJA_SCRIPT_NEXT_PANE_CURRENT_URI " $CAJA_SCRIPT_NEXT_PANE_CURRENT_URI
echo -e "CAJA_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS " $CAJA_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS
echo -e "CAJA_SCRIPT_NEXT_PANE_SELECTED_URIS " $CAJA_SCRIPT_NEXT_PANE_SELECTED_URIS
for((i = 0; i < $numFiles1; i++)); do
echo "--- ${Type1[$i]} ${Files1[$i]}"
done
for((i = 0; i < $numFiles2; i++)); do
echo "--- ${Type2[$i]} ${Files2[$i]}"
done
) >>$T
geany $T &
}
ScanSelectedEntries
# DebugOutput
[ $numFiles1 -eq 2 ] && \
meld "${Files1[0]}" "${Files1[1]}"
[ $numFiles1 -eq 3 ] && \
meld "${Files1[0]}" "${Files1[1]}" "${Files1[2]}"
[ $numFiles1 -eq 1 ] && [ $numFiles2 -eq 1 ] && \
meld "${Files1[0]}" "${Files2[0]}"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment