Difference between revisions of "Feh"

From ArchWiki
Jump to: navigation, search
(Random background image)
(don't write in 1st person, don't sign edits in articles, update templates, see Help:Style)
Line 23: Line 23:
  
 
The script assumes the first argument is the filename.
 
The script assumes the first argument is the filename.
<pre>
+
{{bc|<nowiki>
 
#!/bin/bash
 
#!/bin/bash
  
Line 47: Line 47:
  
 
exec feh "$@" -- "${arr[@]:c}" "${arr[@]:0:c}"
 
exec feh "$@" -- "${arr[@]:c}" "${arr[@]:0:c}"
</pre>
+
</nowiki>}}
  
 
Invoke the script with the selected image's path, followed by any additional arguments to feh. Here is an example of a launcher that you can use in a file browser:
 
Invoke the script with the selected image's path, followed by any additional arguments to feh. Here is an example of a launcher that you can use in a file browser:
Line 72: Line 72:
 
  --bg-fill FILE
 
  --bg-fill FILE
  
To restore the background on the next session, add the following to your startup file (e.g. {{Filename|~/.xinitrc}}, {{Filename|~/.config/openbox/autostart.sh}}, etc.):
+
To restore the background on the next session, add the following to your startup file (e.g. {{ic|~/.xinitrc}}, {{ic|~/.config/openbox/autostart.sh}}, etc.):
 
  sh ~/.fehbg &
 
  sh ~/.fehbg &
  
To change the background image, edit the file {{Filename|~/.fehbg}} which gets created after running the command {{Ic|feh --bg-scale /path/to/image.file}} mentioned above.
+
To change the background image, edit the file {{ic|~/.fehbg}} which gets created after running the command {{Ic|feh --bg-scale /path/to/image.file}} mentioned above.
  
 
====Random background image====
 
====Random background image====
To rotate the wallpaper randomly, create a script with the code below (e.g. {{Filename|wallpaper.sh}}). Make the script executable ({{Ic|chmod +x wallpaper.sh}}) and call it from {{Filename|~/.xinitrc}}. You can also put the source directly in {{Filename|~/.xinitrc}} instead of in a separate file.
+
To rotate the wallpaper randomly, create a script with the code below (e.g. {{ic|wallpaper.sh}}). Make the script executable ({{Ic|chmod +x wallpaper.sh}}) and call it from {{ic|~/.xinitrc}}. You can also put the source directly in {{ic|~/.xinitrc}} instead of in a separate file.
  
Change the {{Filename|~/.wallpaper}} directory to fit your setup and the {{Ic|15m}} delay as you please (see {{Ic|man sleep}} for options).
+
Change the {{ic|~/.wallpaper}} directory to fit your setup and the {{Ic|15m}} delay as you please (see {{Ic|man sleep}} for options).
<pre>
+
{{bc|<nowiki>
 
#!/bin/sh
 
#!/bin/sh
  
Line 89: Line 89:
 
sleep 15m
 
sleep 15m
 
done
 
done
</pre>
+
</nowiki>}}
  
N.B. I had to change '''find ~/.wallpaper''' to '''find ~/.wallpaper/''' to make the above work [[User:Therealplato|Therealplato]] 14:32, 20 January 2012 (EST)
+
You may have to change {{ic|find ~/.wallpaper}} to {{ic|find ~/.wallpaper/}} to make the above work.
  
 
This version does not fork as much, but this version does not recurse through directories:
 
This version does not fork as much, but this version does not recurse through directories:
<pre>
+
{{bc|1=
 
#!/bin/bash
 
#!/bin/bash
  
Line 104: Line 104:
 
files=()
 
files=()
 
for i in *.jpg *.png; do
 
for i in *.jpg *.png; do
[[ -f $i ]] && files+=("$i")
+
<nowiki>[[ -f $i ]]</nowiki> && files+=("$i")
 
done
 
done
 
range=${#files[@]}
 
range=${#files[@]}
Line 112: Line 112:
 
sleep 15m
 
sleep 15m
 
done
 
done
</pre>
+
}}

Revision as of 11:11, 21 January 2012

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

feh is available in the official repositories.

Usage

feh is highly configurable. For a full list of options, run feh --help.

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 file name

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

File Browser Image Launcher

The following script, originally posted on the forum, 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.

The script assumes the first argument is the filename.

#!/bin/bash

shopt -s nullglob

if [[ ! -f $1 ]]; then
	echo "$0: first argument is not a file" >&2
	exit 1
fi

file=$(basename -- "$1")
dir=$(dirname -- "$1")
arr=()
shift

cd -- "$dir"

for i in *; do
	[[ -f $i ]] || continue
	arr+=("$i")
	[[ $i == $file ]] && c=$((${#arr[@]} - 1))
done

exec feh "$@" -- "${arr[@]:c}" "${arr[@]:0:c}"

Invoke the script with the selected image's 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 automatically zooms the image. Adding the -q flag (quiet) suppresses error messages to the terminal when feh tries loading non-image files from the current folder.

As a desktop wallpaper manager

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

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. ~/.xinitrc, ~/.config/openbox/autostart.sh, etc.):

sh ~/.fehbg &

To change the background image, edit the file ~/.fehbg which gets created after running the command feh --bg-scale /path/to/image.file mentioned above.

Random background image

To rotate the wallpaper randomly, create a script with the code below (e.g. wallpaper.sh). Make the script executable (chmod +x wallpaper.sh) and call it from ~/.xinitrc. You can also put the source directly in ~/.xinitrc instead of in a separate file.

Change the ~/.wallpaper directory to fit your setup and the 15m delay as you please (see man sleep for options).

#!/bin/sh

while true; do
	find ~/.wallpaper -type f \( -name '*.jpg' -o -name '*.png' \) -print0 |
		shuf -n1 -z | xargs -0 feh --bg-scale
	sleep 15m
done

You may have to change find ~/.wallpaper to find ~/.wallpaper/ to make the above work.

This version does not fork as much, but this version does not recurse through directories:

#!/bin/bash

shopt -s nullglob
 
cd ~/.wallpaper

while true; do
	files=()
	for i in *.jpg *.png; do
		[[ -f $i ]] && files+=("$i")
	done
	range=${#files[@]}

	((range)) && feh --bg-scale "${files[RANDOM % range]}"

	sleep 15m
done