Blame


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