Difference between revisions of "Sxiv"

From ArchWiki
Jump to navigation Jump to search
(sxiv now honors the XDG base directory specification)
(The latest version of sxiv added a desktop entry)
Line 77: Line 77:
echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}"
echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}"
=== Creating a desktop entry ===
Using a desktop environment some users may prefer to have ''sxiv'' listed in the start menu or list of installed programs. This can be done easily by creating the following {{ic|~/.local/share/applications/sxiv.desktop}} file:
[Desktop Entry]
Comment=A Simple X Image Viewer
Exec=sxiv %f
{{Tip|You can modify {{ic|1=Exec=sxiv %f}} in order to use a user friendly [[#Browse_through_images_in_directory_after_opening_a_single_file|script]].}}
As for the icon, you can for example take [https://github-camo.global.ssl.fastly.net/7da9a42099cafc9a8a66b97d2a6d7f7f95d0a79d/687474703a2f2f6d75656e6e6963682e6769746875622e636f6d2f737869762f696d672f696d6167652e706e67 this] image and place it in {{ic|~/.local/share/icons/hicolor/''size''/apps/sxiv.png}}
== See also ==
== See also ==
* Arch Linux [https://bbs.archlinux.org/viewtopic.php?id=112643 forum thread].
* Arch Linux [https://bbs.archlinux.org/viewtopic.php?id=112643 forum thread].

Revision as of 06:20, 21 February 2014

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary heading Template:Article summary text Template:Article summary end

sxiv, Simple X Image Viewer is a lightweight and scriptable image viewer written in C.


Install sxiv, which is available in the official repositories.

Assigning keyboard shortcuts to sxiv

Note: Currently you need to use sxiv-gitAUR from AUR for this feature to work.

When unrecognised key combos are pressed, sxiv will try to execute the file ~/.config/sxiv/exec/key-handler if it exists, passing the combo pressed and the name of the current image as arguments.

In this example, we will add the bindings Ctrl+d to execute mv filename ~/.trash, Ctrl+c to copy the current image's name to the clipboard with xclip, and Ctrl+w to set the current wallpaper with nitrogen.


case "$1" in
        mv "$2" ~/.trash ;;
        echo -n "$2" | xclip -selection clipboard ;;
        nitrogen --save --set-zoom-fill "$2" ;;

Be sure to mark the script as executable

$ chmod +x ~/.config/sxiv/exec/key-handler

Create .trash folder if it does not exist:

$ mkdir ~/.trash
Tip: You may want to use a standards-compliant trashcan (like trash-cliAUR or bashtrashAUR) rather than mv "$2" ~/.trash.

Tips and tricks

Browse through images in directory after opening a single file

Place this script in /usr/local/bin and call it like this:

$ scriptname a_single_image.jpg

Alternatively you can also install the script as a package from the AUR: sxiv-rifleAUR.

As indicated in the comments of the script, it may be used to have this behavior when opening images from within ranger.

Showing the image size in the status bar

Place the following executable script in ~/.config/sxiv/exec/image-info and make sure that you have the exiv2 package installed:


# Example for ~/.config/sxiv/exec/image-info
# Called by sxiv(1) whenever an image gets loaded,
# with the name of the image file as its first argument.
# The output is displayed in sxiv's status bar.

s=" | " # field separator

filename=$(basename "$1")
filesize=$(du -Hh "$1" | cut -f 1)

geometry=$(identify -format '%wx%h' "$1[0]")

tags=$(exiv2 -q pr -pi "$1" | awk '$1~"Keywords" { printf("%s,", $4); }')

echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}"

See also