Blob


1 # Frequently Asked Questions
3 ## How to use Rover to change the current directory of a shell?
5 Rover cannot change the working directory of its calling shell directly.
6 However, we can use the option `--save-cwd` to write the last visited path
7 to a temporary file. Then we can `cd` to that path from the shell itself.
9 The following shell script can be used to automate this mechanism.
10 Note that it needs to be sourced directly from the shell.
12 ```
13 #! /bin/sh
15 # Based on ranger launcher.
17 # Usage:
18 # . ./cdrover.sh [/path/to/rover]
20 tempfile="$(mktemp 2> /dev/null || printf "/tmp/rover-cwd.%s" $$)"
21 if [ $# -gt 0 ]; then
22 rover="$1"
23 shift
24 else
25 rover="rover"
26 fi
27 "$rover" --save-cwd "$tempfile" "$@"
28 returnvalue=$?
29 test -f "$tempfile" &&
30 if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
31 cd "$(cat "$tempfile")"
32 fi
33 rm -f -- "$tempfile"
34 return $returnvalue
35 ```
37 ## How to open files with appropriate applications?
39 Rover doesn't have any built-in functionality to associate file types with
40 applications. This is delegated to an external tool, designated by the
41 environmental variable `$ROVER_OPEN`. This tool must be a command that
42 takes a filename as argument and runs the appropriate program, opening the
43 given file.
45 As an example, the following shell script may be used as `$ROVER_OPEN`:
47 ```
48 #! /bin/sh
50 # Usage:
51 # ./open.sh /path/to/file
53 case "$1" in
54 *.htm|*.html)
55 fmt="elinks %s" ;;
56 *.pdf|*.xps|*.cbz|*.epub)
57 fmt="mutool draw -F txt %s | less" ;;
58 *.ogg|*.flac|*.wav|*.mp3)
59 fmt="play %s" ;;
60 *.[1-9])
61 fmt="man -l %s" ;;
62 *.c|*.h|*.sh|*.lua|*.py|*.ml|*[Mm]akefile)
63 fmt="vim %s" ;;
64 *)
65 fmt="less %s"
66 esac
68 exec sh -c "$(printf "$fmt" "\"$1\"")"
69 ```