Difference between revisions of "Sxiv"

From ArchWiki
Jump to: navigation, search
m (Script bug)
m (Style fixes.)
Line 17: Line 17:
 
== Assigning keyboard shortcuts to sxiv ==
 
== Assigning keyboard shortcuts to sxiv ==
  
sxiv is scriptable, but to do this, you have to edit {{ic|config.h}} and compile sxiv as follows. See [[ABS]] for details on customizing official packages.
+
''sxiv'' is scriptable, but to do this, you have to edit {{ic|config.h}} and compile ''sxiv'' as follows. See [[ABS]] for details on customizing official packages.
  
In this example, the following command to {{ic|Ctrl+d}}: {{ic|mv file ~/.trash}}, and {{ic|echo -n file | 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 file}} to set the current image as wallpaper with {{ic|CTRL+w}}  
+
In this example, the following command to {{ic|Ctrl+d}}: {{ic|mv file ~/.trash}}, and {{ic|echo -n file | 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 file}} to set the current image as wallpaper with {{ic|Ctrl+w}}  
  
So when sxiv is started in thumbnail mode on a folder, one can see all files in that folder, select random thumbnails, and hit {{ic|CTRL+d}} to move them to a custom "trash" folder.
+
So when ''sxiv'' is started in thumbnail mode on a folder, one can see all files in that folder, select random thumbnails, and hit {{ic|Ctrl+d}} to move them to a custom "trash" folder.
  
Edit config.h, to add the line for the {{ic|d}} and {{ic|c}} shortcut:
+
Edit {{ic|config.h}}, to add the line for the {{ic|d}} and {{ic|c}} shortcut:
{{hc|head=config.h|output=<nowiki>
+
{{hc|config.h|<nowiki>
 
         /* run shell command line on current file ("$SXIV_IMG"): */
 
         /* run shell command line on current file ("$SXIV_IMG"): */
 
         { true,  XK_less,          it_shell_cmd,        (arg_t) \
 
         { true,  XK_less,          it_shell_cmd,        (arg_t) \
Line 44: Line 44:
 
</nowiki>}}
 
</nowiki>}}
  
Create .trash folder if it doesn't exist:
+
Create {{ic|.trash}} folder if it does not exist:
 
  $ mkdir ~/.trash
 
  $ mkdir ~/.trash
  
Now when you start sxiv in thumbnail mode on a folder of pictures, i.e.:
+
{{Tip|Yu may want to use a standard compliant trasher (like {{AUR|trash-cli}} or {{AUR|bashtrash}}) instead of {{ic|mv \"$SXIV_IMG\" ~/.trash}}.}}
 +
 
 +
Now when you start ''sxiv'' in thumbnail mode on a folder of pictures, i.e.:
 
  $ sxiv -tsr ~/pictures
 
  $ sxiv -tsr ~/pictures
  
Line 63: Line 65:
 
=== Showing the image size in the status bar ===
 
=== Showing the image size in the status bar ===
  
Place the following executable script in {{ic|~/.sxiv/exec/image-info}} and make sure that you have the {{pkg|exiv2}} package installed:
+
Place the following executable script in {{ic|~/.sxiv/exec/image-info}} and make sure that you have the {{Pkg|exiv2}} package installed:
  
 
{{hc|~/.sxiv/exec/image-info|<nowiki>
 
{{hc|~/.sxiv/exec/image-info|<nowiki>
Line 83: Line 85:
 
tags=${tags%,}
 
tags=${tags%,}
  
echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}"</nowiki>
+
echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}"
}}
+
</nowiki>}}
 +
 
 
=== Creating a desktop entry ===
 
=== 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:  
+
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]
 
  [Desktop Entry]
Line 99: Line 102:
 
  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;
 
  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;
  
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}}
+
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 21:14, 19 November 2013

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, but to do this, you have to edit config.h and compile sxiv as follows. See ABS for details on customizing official packages.

In this example, the following command to Ctrl+d: mv file ~/.trash, and echo -n file to put the full path and filename of the current image into the clipboard with Ctrl+c, and nitrogen --save --set-zoom-fill file to set the current image as wallpaper with Ctrl+w

So when sxiv is started in thumbnail mode on a folder, one can see all files in that folder, select random thumbnails, and hit Ctrl+d to move them to a custom "trash" folder.

Edit config.h, to add the line for the d and c shortcut:

config.h
        /* run shell command line on current file ("$SXIV_IMG"): */
        { true,   XK_less,          it_shell_cmd,         (arg_t) \
                        "mogrify -rotate -90 \"$SXIV_IMG\"" },
        { true,   XK_greater,       it_shell_cmd,         (arg_t) \
                        "mogrify -rotate +90 \"$SXIV_IMG\"" },
        { true,   XK_comma,         it_shell_cmd,         (arg_t) \
                        "jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
        { true,   XK_period,        it_shell_cmd,         (arg_t) \
                        "jpegtran -rotate  90 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
//insert the lines below
        { true,   XK_d,             it_shell_cmd,         (arg_t) \
                        "mv \"$SXIV_IMG\" ~/.trash" },
        { true,   XK_c,             it_shell_cmd,         (arg_t) \
                        "echo -n \"$SXIV_IMG\" | xclip" },
        { true,   XK_w,             it_shell_cmd,         (arg_t) \
                        "nitrogen --save --set-wallpaper \"$SXIV_IMG\"" },
};

Create .trash folder if it does not exist:

$ mkdir ~/.trash
Tip: Yu may want to use a standard compliant trasher (like trash-cliAUR or bashtrashAUR) instead of mv \"$SXIV_IMG\" ~/.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 Ctrl+d. This will move your selected pic to ~/.trash. Pressing Ctrl+c copies the full path and file name of the current picture to the clipboard. Pressing Ctrl+w will make the set the picture as wallpaper using Nitrogen.

Tips and tricks

Browse through images in directory after opening a single file

Place this script in $PATH and call it like this:

$ scriptname a_single_image.jpg
Warning: This script may not work with some characters, like .

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;

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