Feh

From ArchWiki
Revision as of 15:44, 28 January 2011 by Xyne (Talk | contribs) (added file browser launcher script from forum)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

feh is a lightweight and powerful image viewer that can also be used to manage the desktop wallpaper for standalone window managers lacking such features.

Installation

Template:Package Official is available in Extra:

# pacman -S feh

Usage

feh is highly configurable. For a full list of options, run Template:Codeline.

As an image viewer

To quickly browse images in a specific directory, you can launch feh with the following arguments:

$ feh -g 640x480 -d -S filename /path/to/directory
  • The -g flag forces the images to appear no larger than 640x480
  • The -S filename flag sorts the images by filename

This is just one example; there are many more options available should you desire more flexibility.

File Browser Image Launcher

Originally posted by Xyne, the following script is useful for file browsers. It will display your selected image in feh, but it will enable you to browse all other images in the directory as well, in their default order, i.e. as if you had run "feh *" and cycled through to the selected image.

 #!/bin/bash
 
 # Change the input field separator to avoid problems with spaces.
 IFS='
 '
 # Get the target file, its name, directory, and the other files in the
 directory.
 _fpath="${1/%\/}"
 _fname="$(basename "$_fpath")"
 _dpath="$(dirname "$_fpath")"
 _flist=($(ls "$_dpath"))
 
 
 # Determine the index of the target file in the file list array.
 _i=0
 for _file in "${_flist[@]}"; do
   [ "$_file" == "$_fname" ] && break
   _i=$(($_i + 1))
 done
 
 # Remove the target file from the arguments, leaving any eventual arguments to
 # feh.
 shift
 
 # Change to the directory and launch feh with the target file as the first
 # argument, and the rest of the files in their normal order.
 cd "$_dpath"
 feh "$@"  "${_flist[@]:$_i}" "${_flist[@]:0:$_i}"


Invoke the script with the selected images path, followed by any additional arguments to feh. Here is an example of a launcher that you can use in a file browser:

 /path/to/script %f -F -Z

"-F" and "-Z" are feh arguments. "-F" opens the image in fullscreen mode, and "-Z" autozooms the image.

As a desktop wallpaper manager

feh can be used to manage the desktop wallpaper for window managers that lack desktop features, such as Openbox and Fluxbox.

When using GNOME, you must disable Nautilus from controlling the desktop. The easiest way is to run this command:

$ gconftool-2 --set /apps/nautilus/preferences/show_desktop --type boolean false

The following command is an example of how to set the initial background:

$ feh --bg-scale /path/to/image.file

Other scaling options include:

--bg-tile FILE
--bg-center FILE
--bg-max FILE
--bg-fill FILE

To restore the background on the next session, add the following to your startup file (e.g. Template:Filename, Template:Filename, etc.):

sh ~/.fehbg &

Random background image

To rotate the wallpaper randomly, create a script with the code below (e.g. Template:Filename). Make the script executable (Template:Codeline) and call it from Template:Filename. You can also put the source directly in Template:Filename instead of in a separate file.

Change the Template:Filename directory to fit your setup, and the "15m" delay as you please (see Template:Codeline for options).

#!/bin/sh
while true;
do
   find $HOME/.wallpaper -type f -name '*.jpg' -o -name '*.png' | shuf -n 1 | xargs feh --bg-scale
   sleep 15m
done &

If you have spaces in the file names try this:

#!/bin/sh
while true;
do
   feh --bg-scale "$(find ~/.wallpaper -name *.jpg | shuf -n 1)"
   sleep 15m
done &

This should also work with spaces:

#!/bin/sh
while true;
do
   find $HOME/.wallpaper -type f \( -name '*.jpg' -o -name '*.png' \) -print0 | shuf -n 1 -z | xargs -0 feh --bg-scale
   sleep 15m
done &

Another script, written by Wisp558, that includes a timer and allows spaces:

#!/bin/bash

DIR=/home/wisp/Wallpapers
FLOOR=1
RANGE=`ls -1 "$DIR"/*.jpg "$DIR"/*.png | wc | awk '// {print $1}'`

number=0

while [ 1 -eq 1 ]; do
	
	number=$RANDOM
	while [ "$number" -le $FLOOR ]; do
  		number=$RANDOM
	done
	let "number %= $RANGE"  # Scales $number down within $RANGE.
	COUNTER=1
	for X in "$DIR"/*.jpg "$DIR"/*.png
	do
		if [ $number -eq $COUNTER ]; then
			feh --bg-scale "$X"
		fi
	COUNTER=$(($COUNTER+1))
	done
	COUNTER=1
	sleep 2m
done