Difference between revisions of "Sxiv"

From ArchWiki
Jump to: navigation, search
(Assigning keyboard shortcuts to sxiv)
(Installation: add sxiv-git)
 
(47 intermediate revisions by 18 users not shown)
Line 1: Line 1:
[[Category:Graphics and desktop publishing]]
 
 
{{Lowercase title}}
 
{{Lowercase title}}
{{Article summary start}}
+
[[Category:Image manipulation]]
{{Article summary text|This article discusses the installation and basic configuration of {{Pkg|sxiv}}.}}
+
[[ja:Sxiv]]
{{Article summary heading|Related}}
+
{{Related articles start}}
{{Article summary wiki|feh}}
+
{{Related|feh}}
{{Article summary heading|External Links}}
+
{{Related articles end}}
{{Article summary text| [http://github.com/muennich/sxiv sxiv on github]}}
+
{{Article summary end}}
+
  
'''sxiv''', Simple [[X]] Image Viewer is a lightweight image viewer written in C. It is a lightweight image viewer that is scriptable.  
+
[http://github.com/muennich/sxiv sxiv] , Simple [[X]] Image Viewer is a lightweight and scriptable image viewer written in C.  
  
 
== Installation ==
 
== Installation ==
  
[[pacman|Install]] {{pkg|sxiv}}, which is available in the [[Official Repositories|official repositories]].
+
[[Install]] the {{Pkg|sxiv}} package, or {{AUR|sxiv-git}} for the development version.
  
== Assigning keyboard shortcuts to sxiv ==
+
== Usage ==
  
sxiv is scriptable, but to do this, you have to edit config.h and compile sxiv as follows:
+
=== Assigning keyboard shortcuts ===
  
As an example we will assign the following command to {{Keypress|^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 {{Keypress|^c}}, and {{ic|nitrogen --save --set-zoom-fill file}} to set the current image as wallpaper with {{Keypress|CTRL+W}}
+
sxiv supports external key events. First you have to press {{ic|Ctrl-x}} to send the next key to the external key-handler. The external key-handler requires an executable file {{ic|~/.config/sxiv/exec/key-handler}} and passes the key combination pressed via argument as well the names of the currently marked images as stdin (or, if none are marked, the currently selected image).
  
So when sxiv is started in thumbnail mode on a folder, one can see all files in that folder, select random thumbnails, and hit ^d to move them to a custom "trash" folder.
+
In this example, we will add the bindings {{ic|Ctrl+d}} to execute {{ic|mv ''filename'' ~/.trash}}, {{ic|Ctrl+c}} to copy the current images' names to the clipboard with {{Pkg|xclip}}, and {{ic|Ctrl+w}} to set the current wallpaper with [[nitrogen]]. Obviously, some commands may only make sense with a single image as an argument, so you may want to revise this to handle cases when those are passed more than one.
  
=== Tutorial ===
+
{{hc|~/.config/sxiv/exec/key-handler|<nowiki>
 +
#!/bin/sh
 +
while read file
 +
do
 +
        case "$1" in
 +
        "C-d")
 +
                mv "$file" ~/.trash ;;
 +
        "C-r")
 +
                convert -rotate 90 "$file" "$file" ;;
 +
        "C-c")
 +
                echo -n "$file" | xclip -selection clipboard ;;
 +
        "C-w")
 +
                nitrogen --save --set-zoom-fill "$file" ;;
 +
        esac
 +
done
 +
</nowiki>}}
  
Get latest PKGBUILD from abs
+
Be sure to mark the script as executable
# abs community/sxiv
+
{{Note|The prompt above is a root prompt, denoted by a pound-sign (#), so you may have to use {{ic|sudo}}, for example.}}
+
  
copy source to your own workspace:
+
  $ chmod +x ~/.config/sxiv/exec/key-handler
  $ cp -r /var/abs/community/sxiv ~/sources
+
  
move to source directory to start the work:
+
Create {{ic|.trash}} folder if it does not exist:
$ cd ~/sources/sxiv
+
  
edit config.h, to add the line for the "d" and "c" shortcut:
+
  $ mkdir ~/.trash
{{Hc|head=config.h|output=<nowiki>
+
        /* 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\"" },
+
};</nowiki>}}
+
  
After saving config.h, create new checksums for modified files (config.h in this case):
+
{{Tip|You may want to use a [http://freedesktop.org/wiki/Specifications/trash-spec/ standards-compliant trashcan] (like {{Pkg|trash-cli}} or {{AUR|bashtrash}}) rather than {{ic|mv "$2" ~/.trash}}.}}
$ makepkg -g >> PKGBUILD
+
  
Extract the source files; you can just run makepkg to do it for you:
+
== Tips and tricks ==
$ makepkg
+
  
Compile sxiv and install it:
+
=== Browse through images in directory after opening a single file ===
$ makepkg -efi
+
  
Create .trash folder if it doesn't exist:
+
Place [https://github.com/ranger/ranger/blob/master/examples/rifle_sxiv.sh this script] in {{ic|/usr/local/bin}} and call it like this:
$ mkdir ~/.trash
+
  
Now when you start sxiv in thumbnail mode on a folder of pictures, i.e.:
+
  $ ''scriptname'' a_single_image.jpg
  $ sxiv -tsr ~/pictures
+
  
Congratulations, you can now delete selected pictures by hitting {{Keypress|CTRL+D}}. This will move your selected pic to ~/.trash. Pressing {{Keypress|CTRL+C}} copies the full path and file name of the current picture to the clipboard. Pressing {{Keypress|CTRL+W}} will make the set the picture as wallpaper using Nitrogen.
+
Alternatively you can also install the script as a package from the AUR: {{AUR|sxiv-rifle}}.  
  
==Tips and Tricks==
 
===Browse through images in directory after opening a single file===
 
Place [http://git.savannah.gnu.org/cgit/ranger.git/tree/doc/examples/rifle_sxiv.sh this script] in $PATH and call it like this:
 
$ <scriptname> a_single_image.jpg
 
 
As indicated in the comments of the script, it may be used to have this behavior when opening images from within [[ranger]].
 
As indicated in the comments of the script, it may be used to have this behavior when opening images from within [[ranger]].
  
==See also==
+
=== Showing the image size in the status bar ===
 +
 
 +
Place the following executable script in {{ic|~/.config/sxiv/exec/image-info}} and make sure that you have the {{Pkg|exiv2}} package installed:
 +
 
 +
{{hc|~/.config/sxiv/exec/image-info|<nowiki>
 +
#!/bin/sh
 +
 
 +
# 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); }')
 +
tags=${tags%,}
 +
 
 +
echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}"
 +
</nowiki>}}
 +
 
 +
== 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].
 +
* Sxiv for keyboard layout [[wikipedia:Keyboard_layout#B.C3.89PO|bépo]] (keyboard layout in the spirit of [[wikipedia:Dvorak_Simplified_Keyboard|Dvorak]] for french speakers) : [http://bepo.fr/wiki/Vim#Visionneuse_d.27image_Sxiv Sxiv bépo].

Latest revision as of 13:37, 5 July 2016

Related articles

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

Installation

Install the sxiv package, or sxiv-gitAUR for the development version.

Usage

Assigning keyboard shortcuts

sxiv supports external key events. First you have to press Ctrl-x to send the next key to the external key-handler. The external key-handler requires an executable file ~/.config/sxiv/exec/key-handler and passes the key combination pressed via argument as well the names of the currently marked images as stdin (or, if none are marked, the currently selected image).

In this example, we will add the bindings Ctrl+d to execute mv filename ~/.trash, Ctrl+c to copy the current images' names to the clipboard with xclip, and Ctrl+w to set the current wallpaper with nitrogen. Obviously, some commands may only make sense with a single image as an argument, so you may want to revise this to handle cases when those are passed more than one.

~/.config/sxiv/exec/key-handler
#!/bin/sh
while read file
do
        case "$1" in
        "C-d")
                mv "$file" ~/.trash ;;
        "C-r")
                convert -rotate 90 "$file" "$file" ;;
        "C-c")
                echo -n "$file" | xclip -selection clipboard ;;
        "C-w")
                nitrogen --save --set-zoom-fill "$file" ;;
        esac
done

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-cli 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:

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

# 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); }')
tags=${tags%,}

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

See also