From ArchWiki
Jump to: navigation, search

File Browser Image Launcher

After this revision, the script was no longer usable. This was noted on the forum by a user who had tried the script.

  • Do not post scripts that you have not tested, especially when replacing a working script.
  • Giving credit is not "pimping". Respect others and their contributions.
  • Comments that include "sweet jesus" and disparaging terms are inappropriate . Given that the changes broke the script, they are also ironic.

unsigned comment

The only substantial change were the quotation marks, which are completely superficial since word expansion does not occur in double-brackets, and that's covered in the bash manual. There's plenty of content in the wiki, some of it of varying quality, and if everybody placed their name besides it, I'd say they had it coming. I'm not going to address the supossed brokenness since the previous itineration didn't handle name's with [[:space:]], at all. Stick to perl :) Lavandero 11:59, 1 February 2011 (EST)

Following are a few problems with the current version of the script, along with my proposed changes:

  • Does not handles filenames with embedded spaces.
    • Change the field separator, $IFS
    • Quote your variables
  • Passes to feh all files in the folder, including those of types that feh can't read. In a folder with many of these, the result is that feh seems to be frozen unless one presses the space bar enough times to reach the next readable file.
    • Check the mime type of each file against what is associated with feh. The only way I knew to do this turned out to be agonizingly slow, but I retained the lines as comments, for reference.
    • iterate only over files of know file extensions. This has the disadvantage of requiring a user modify the list for any additional mime types, eg. when loading an imlib2 module for ImageMagick
  • Does not properly expand parameters passed to feh.
    • use the bash builtin 'eval' instead of 'exec'
  • Suppress feh text output. This is desirable for situations such as when the script is launched by midnight commander, in which case feh's text output will pollute the file listing screen.

Here's my proposed version. If no one objects within a few days, I'll post it to the wiki page.
# feh_browser
# Display your selected image in feh, and browse all other
# images in the directory as well, in their default order.

# $1 filename
# $* arguments to feh

feh_parms="--draw-filename --draw-exif --magick-timeout 10 --image-bg black -g 800x600 "
shopt -s nullglob
if [[ ! -f $1 ]]; then
  echo "$0: first argument is not a file" >&2
  exit 1
file=$(basename -- "$1")
dir=$(dirname -- "$1")
cd -- "$dir"
IFS=$(echo -en "\n\b")
for i in *.{png,jpg,jpeg,gif} ; do
  [[ -f "${i}" ]] || continue
  # The following was molasses-slow ...
  #  mime_type="$(xdg-mime query filetype "${i}")"
  #  [[ "feh.desktop" ==  "$(xdg-mime query default ${mime_type})" ]] || continue
  [[ "$i" == "$file" ]] && c=$((${#arr[@]} - 1))
eval feh ${feh_parms} $@ -- "${arr[@]:c}" "${arr[@]:0:c}" >/dev/null 2>&1

Boruch (talk) 18:50, 23 August 2016 (UTC)

Feh and "--"

Xyne, you've recently taken out "--", which disallows opening filenames that are the same as flags.

The following is an example run and a source code excerpt that implements "--".

Feh does recognize "--" as the end of flags:

andres@pote:~/torrents/Land of Lisp $ feh -- -F
feh WARNING: -F does not exist - skipping
feh - No loadable images specified.
Use feh --help for detailed usage information
andres@pote:~/torrents/Land of Lisp $

And here's the responsible code in GITROOT/src/getopt.c

	/* The special ARGV-element `--' means premature end of options. Skip
	   it like a null option, then exchange with previous non-options as if 
	   it were an option, then skip everything else like a non-option.  */

	if (optind != argc && !strcmp(argv[optind], "--")) {

		if (first_nonopt != last_nonopt && last_nonopt != optind)
			exchange((char **) argv);
		else if (first_nonopt == last_nonopt)
			first_nonopt = optind;
		last_nonopt = argc;

		optind = argc;

You can access the feh source repository and the specific file responsible for "--" here. Lavandero 08:01, 5 February 2011 (EST)

Then there is a bug in the code. The inclusion of "--" in the random background script generates the following error:
  feh WARNING: -- - File does not exist
  feh ERROR: Couldn't load image in order to set bg
Until this bug is resolved upstream. "--" should not be included in the script. Again, I ask you to please test your scripts, however trivial the change may be. Pointing to source code files is meaningless if the currently available application does not behave as expected. --Xyne 13:26, 6 February 2011 (EST)

Can't you just use a variable like that?

—This unsigned comment is by Flu (talk) 09:05, 22 October 2012‎. Please sign your posts with ~~~~!