0

Is there a way in any Linux GUI file manager to create a custom shortcut to a bash file to be executed using the selected file(s)?

Example: Create hash sums of this file.

Bash script: makehashsums.bash

(md5sum $@
sha1sum $@
sha512sum $@
cksum $@
sum $@ ) >>[email protected]

These are not all available hashsum algorithms, but the most common ones.

If possible, it would be great if it is supported for multiple files.

How can I add such a custom option to the context menu of a Linux file manager? (Is there one that supports this feature?)

1 Answer 1

1

Depending on your Desktop env it should be fairly simple to add your own scripts to the Open-with dialogue.

enter image description here

For the script itself, you just cycle through the command line arguments. ~/bin/hashies:

#!/bin/bash

# Don't want to get upset by
# whitespace in filenames.
oldIFS=$IFS
IFS=$'\n'

# Cycle through inputs
for file in $*
do
    # Get hashes for the files
    # Store per target file.
    (
        md5sum $file
        sha1sum $file
        sha512sum $file
        cksum $file
        sum $file
    ) > ${file}.hashsums.txt
done

# Probably don't need to bother with
# restoring the input field separator
# as the sub-shell is about to die.
IFS=$oldIFS

2
  • 1
    That should be for file to work with whitespace in file names (it's equivalent to for file in "$@", which is the correct way to loop over arguments). And you don't need to override IFS. Commented Jul 1, 2019 at 8:35
  • Very useful answer, thanks. But can it also be added to the direct context menu that gets shown immediately after the right mouse click? Commented Jul 2, 2019 at 15:14

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.