Difference between revisions of "Sxiv"

From ArchWiki
Jump to navigation Jump to search
(keyboard shortcuts are now handled via external commands)
m (cleanup)
Line 19: Line 19:
 
''sxiv'' is scriptable. When unrecognised key combos are pressed, sxiv will try to execute the file {{ic|~/.sxiv/exec/key-handler}} if it exists, passing the combo pressed and the name of the current image as arguments.
 
''sxiv'' is scriptable. When unrecognised key combos are pressed, sxiv will try to execute the file {{ic|~/.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 commands {{ic|Ctrl+d}} to execute {{ic|mv FILENAME ~/.trash}}, and {{ic|echo -n FILENAME | xclip}} to put the full path and filename of the current image into the clipboard with {{ic|Ctrl+c}}, and {{ic|nitrogen --save --set-zoom-fill FILENAME}} to set the current image as wallpaper with {{ic|Ctrl+w}}
+
In this example, we will add the bindings {{ic|Ctrl+d}} to execute {{ic|mv FILENAME ~/.trash}}, {{ic|Ctrl+c}} to copy the current image's name to the clipboard with {{Pkg|xclip}}, and {{ic|Ctrl+w}} to set the current wallpaper with [[nitrogen]].
  
 
{{hc|~/.sxiv/exec/key-handler|<nowiki>
 
{{hc|~/.sxiv/exec/key-handler|<nowiki>
Line 28: Line 28:
 
         mv "$2" ~/.trash ;;
 
         mv "$2" ~/.trash ;;
 
"C-c")
 
"C-c")
         echo -n "$2" | xclip ;;
+
         echo -n "$2" | xclip -selection clipboard ;;
 
"C-w")
 
"C-w")
 
         nitrogen --save --set-zoom-fill "$2" ;;
 
         nitrogen --save --set-zoom-fill "$2" ;;
Line 40: Line 40:
 
  $ mkdir ~/.trash
 
  $ mkdir ~/.trash
  
{{Tip|You may want to use a standard compliant trashcan (like {{AUR|trash-cli}} or {{AUR|bashtrash}}) instead of {{ic|mv \"$SXIV_IMG\" ~/.trash}}.}}
+
{{Tip|You may want to use a [http://freedesktop.org/wiki/Specifications/trash-spec/ standards-compliant trashcan] (like {{AUR|trash-cli}} or {{AUR|bashtrash}}) rather than {{ic|mv "$2" ~/.trash}}.}}
 
 
Now when you start ''sxiv'' in thumbnail mode on a folder of pictures, i.e.:
 
$ sxiv -tsr ~/pictures
 
 
 
You can now delete selected pictures by hitting {{ic|Ctrl+d}}. This will move your selected pic to {{ic|~/.trash}}. Pressing {{ic|Ctrl+c}} copies the full path and file name of the current picture to the clipboard. Pressing {{ic|Ctrl+w}} will make the set the picture as wallpaper using Nitrogen.
 
  
 
== Tips and tricks ==
 
== Tips and tricks ==

Revision as of 07:06, 6 January 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.

Installation

Install sxiv, which is available in the official repositories.

Assigning keyboard shortcuts to sxiv

sxiv is scriptable. When unrecognised key combos are pressed, sxiv will try to execute the file ~/.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.

~/.sxiv/exec/key-handler
#!/bin/sh

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

Be sure to mark the script as executable

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

Warning: This script may not work with some characters, like . Correct the internal grep options to make it work:
# sed -i 's/grep/grep -a/' /usr/local/bin/scriptname

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 ~/.sxiv/exec/image-info and make sure that you have the exiv2 package installed:

~/.sxiv/exec/image-info
#!/bin/sh

# Example for ~/.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); }')
tags=${tags%,}

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 ~/.local/share/applications/sxiv.desktop file:

[Desktop Entry]
Name=sxiv
Comment=A Simple X Image Viewer
Exec=sxiv %f
Terminal=false
Type=Application
Icon=sxiv
Categories=GTK;Graphics;2DGraphics;Viewer;
MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/pjpeg;image/png;image/tiff;image/x-bmp;image/x-pcx;image/x-png;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-sun-raster;image/x-tga;image/x-xbitmap;image/x-xpixmap;image/svg+xml;
Tip: You can modify Exec=sxiv %f in order to use a user friendly script.

As for the icon, you can for example take this image and place it in ~/.local/share/icons/hicolor/size/apps/sxiv.png

See also