Difference between revisions of "Feh"

From ArchWiki
Jump to: navigation, search
m
(Multiple-monitor setup documented and minor cosmetic updates)
 
(60 intermediate revisions by 26 users not shown)
Line 1: Line 1:
[[Category:Graphics and desktop publishing]]
+
[[Category:Image manipulation]]
 +
[[de:Feh]]
 
[[es:Feh]]
 
[[es:Feh]]
 
[[it:Feh]]
 
[[it:Feh]]
 +
[[ja:Feh]]
 
[[lt:Feh]]
 
[[lt:Feh]]
 
[[ru:Feh]]
 
[[ru:Feh]]
[[zh-CN:Feh]]
+
[[zh-hans:Feh]]
[https://derf.homelinux.org/~derf/projects/feh/ 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.
+
{{Related articles start}}
 +
{{Related|Nitrogen}}
 +
{{Related|sxiv}}
 +
{{Related articles end}}
 +
[http://feh.finalrewind.org/ 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==
+
== Installation ==
{{pkg|feh}} is available in the [[Official Repositories|official repositories]].
 
  
==Usage==
+
[[Install]] the {{pkg|feh}} package.
feh is highly configurable. For a full list of options, run {{Ic|feh --help}}.
+
 
 +
== Usage ==
 +
 
 +
feh is highly configurable. For a full list of options, run {{Ic|feh --help}} or see the {{man|1|feh}} [[man page]].
 +
 
 +
=== Browse images ===
  
===As an image viewer===
 
 
To quickly browse images in a specific directory, you can launch feh with the following arguments:
 
To quickly browse images in a specific directory, you can launch feh with the following arguments:
  
Line 19: Line 28:
  
 
* The {{Ic|-g}} flag forces the images to appear no larger than 640x480
 
* The {{Ic|-g}} flag forces the images to appear no larger than 640x480
 +
* The {{Ic|-d}} flag draws the file name
 
* The {{Ic|-S filename}} flag sorts the images by file name
 
* The {{Ic|-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.
 
This is just one example; there are many more options available should you desire more flexibility.
  
====File Browser Image Launcher====
+
{{Tip|The {{ic|--start-at}} option will display a selected image in feh while allowing 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. For example, {{ic|feh --start-at ./foo.jpg .}} views all images in the current directory, starting with {{ic|''foo''.jpg}}.}}
The following script, originally posted [https://bbs.archlinux.org/viewtopic.php?pid=884635#p884635 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.
 
{{bc|<nowiki>
 
#!/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}"
 
</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:
 
 
 
  /path/to/script %f -F -Z
 
 
 
{{Ic|-F}} and {{Ic|-Z}} are feh arguments. {{Ic|-F}} opens the image in fullscreen mode, and {{Ic|-Z}} automatically zooms the image. Adding the {{Ic|-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:
+
=== Set the wallpaper ===
  
$ gconftool-2 --set /apps/nautilus/preferences/show_desktop --type boolean false
+
{{ic|feh}} can be used to set the desktop wallpaper, for example for [[window manager]]s without this feature such as [[Openbox]], [[Fluxbox]], and [[xmonad]].
  
 
The following command is an example of how to set the initial background:
 
The following command is an example of how to set the initial background:
Line 71: Line 44:
  
 
Other scaling options include:
 
Other scaling options include:
--bg-tile FILE
+
{{bc|
--bg-center FILE
+
--bg-tile FILE
--bg-max FILE
+
--bg-center FILE
--bg-fill FILE
+
--bg-max FILE
 +
--bg-fill FILE
 +
}}
  
 
To restore the background on the next session, add the following to your startup file (e.g. {{ic|~/.xinitrc}}, {{ic|~/.config/openbox/autostart}}, etc.):
 
To restore the background on the next session, add the following to your startup file (e.g. {{ic|~/.xinitrc}}, {{ic|~/.config/openbox/autostart}}, etc.):
  sh ~/.fehbg &
+
 
 +
  $ ~/.fehbg &
  
 
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.
 
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====
+
One can explicitly disable the creation of the {{ic|~/.fehbg}}, by passing the {{ic|--no-fehbg}} flag as well.
To rotate the wallpaper randomly, create a script with the code below (e.g. {{ic|wallpaper.sh}}). Make the script executable:
 
  
$ chmod +x wallpaper.sh
+
To setup different wallpapers for different monitors one should pass as many file paths as many monitors are available. For example, for a dual monitor setup it would be:
  
and call it from {{ic|~/.xinitrc}}. You can also put the source directly in {{ic|~/.xinitrc}} instead of in a separate file.
+
$ feh --bg-center path/to/file/for/first/monitor path/to/file/for/second/monitor
  
Change the {{ic|~/.wallpaper}} directory to fit your setup and the {{Ic|15m}} delay as you please (see {{Ic|man sleep}} for options).
+
=== Open SVG images ===
{{bc|<nowiki>
 
#!/bin/sh
 
  
while true; do
+
{{bc|$ feh --magick-timeout 1 file.svg}}
find ~/.wallpaper -type f \( -name '*.jpg' -o -name '*.png' \) -print0 |
+
 
shuf -n1 -z | xargs -0 feh --bg-max
+
Note that this requires the {{Pkg|imagemagick}} package.
sleep 15m
+
 
done
+
=== Random background image ===
</nowiki>}}
 
  
You may have to change {{ic|find ~/.wallpaper}} to {{ic|find ~/.wallpaper/}} to make the above work.
+
You can have feh set a random wallpaper using the {{ic|--randomize}} option with one of the {{ic|--bg-foo}} options, for example:
  
This version does not fork as much, but this version does not recurse through directories:
+
{{bc|$ feh --randomize --bg-fill ~/.wallpaper/*}}
{{bc|1=
 
#!/bin/bash
 
  
shopt -s nullglob
+
The above command tells feh to randomize the list of files in the {{ic|~/.wallpaper/}} directory and set the backgrounds for all available desktops to whichever images are at the front of the randomized list (one unique image for each desktop). You can also do this recursively, if you have your wallpapers divided into subfolders:
 
cd ~/.wallpaper
 
  
while true; do
+
{{bc|$ feh --recursive --randomize --bg-fill ~/.wallpaper}}
files=()
 
for i in *.jpg *.png; do
 
<nowiki>[[ -f $i ]]</nowiki> && files+=("$i")
 
done
 
range=${#files[@]}
 
  
((range)) && feh --bg-scale "${files[RANDOM % range]}"
+
To set a different random wallpaper from {{ic|~/.wallpaper}} each session, add the following to your {{ic|.xinitrc}}:
  
sleep 15m
+
{{bc|$ feh --bg-max --randomize ~/.wallpaper/* &}}
done
 
}}
 
=====Using a cron job=====
 
Using a cron job, you can get a similar result, and it does not require having a script constantly sleeping.
 
  
Just do crontab -e and add:
+
Another way to set a random wallpaper on each x.org session is to edit your {{ic|.fehbg}} as following.
 +
{{hc|$HOME/.fehbg|<nowiki>
 +
feh --bg-max --randomize --no-fehbg ~/.wallpaper/*
 +
</nowiki>}}
  
* * * * *  DISPLAY=:0.0 feh --bg-max "$(find ~/.wallpaper/|shuf -n1)"
+
{{Tip|To change wallpapers periodically, use a script (see [http://mywiki.wooledge.org/BashGuide/TestsAndConditionals#Conditional_Loops_.28while.2C_until_and_for.29 while loop]), [[cron]] job, or [[systemd/Timers|systemd timer]] to execute the command at the desired interval.}}

Latest revision as of 15:24, 3 December 2017

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

Install the feh package.

Usage

feh is highly configurable. For a full list of options, run feh --help or see the feh(1) man page.

Browse images

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 -d flag draws the file name
  • 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.

Tip: The --start-at option will display a selected image in feh while allowing 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. For example, feh --start-at ./foo.jpg . views all images in the current directory, starting with foo.jpg.

Set the wallpaper

feh can be used to set the desktop wallpaper, for example for window managers without this feature such as Openbox, Fluxbox, and xmonad.

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, etc.):

$ ~/.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.

One can explicitly disable the creation of the ~/.fehbg, by passing the --no-fehbg flag as well.

To setup different wallpapers for different monitors one should pass as many file paths as many monitors are available. For example, for a dual monitor setup it would be:

$ feh --bg-center path/to/file/for/first/monitor path/to/file/for/second/monitor

Open SVG images

$ feh --magick-timeout 1 file.svg

Note that this requires the imagemagick package.

Random background image

You can have feh set a random wallpaper using the --randomize option with one of the --bg-foo options, for example:

$ feh --randomize --bg-fill ~/.wallpaper/*

The above command tells feh to randomize the list of files in the ~/.wallpaper/ directory and set the backgrounds for all available desktops to whichever images are at the front of the randomized list (one unique image for each desktop). You can also do this recursively, if you have your wallpapers divided into subfolders:

$ feh --recursive --randomize --bg-fill ~/.wallpaper

To set a different random wallpaper from ~/.wallpaper each session, add the following to your .xinitrc:

$ feh --bg-max --randomize ~/.wallpaper/* &

Another way to set a random wallpaper on each x.org session is to edit your .fehbg as following.

$HOME/.fehbg
 feh --bg-max --randomize --no-fehbg ~/.wallpaper/* 
Tip: To change wallpapers periodically, use a script (see while loop), cron job, or systemd timer to execute the command at the desired interval.