aboutsummaryrefslogtreecommitdiff
path: root/man/man1/apf.1df
blob: 025af010e594c80176b2902bed9fed318a26434f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.TH APF 1df "August 2016" "Manual page for apf"
.SH NAME
.B apf
\- add arguments to a command from a file
.SH SYNOPSIS
.B apf
foorc
foo --bar baz
.SH DESCRIPTION
Add newline-delimited arguments read from a file to a command's arguments
(before any given ones) before running it. This is intended as a quick way of
implementing *rc files for interactive shell calls to programs that don't
support such files, without having to use broken environment variables like GNU
grep(1)'s GREP_OPTIONS.
.P
This enables you to use arguments with shell metacharacters and spaces in them
that you do not want expanded. The only exception is that you cannot have
newlines in any of the arguments. This was done to keep POSIX sh(1)
compatibility.
.P
For example, given this simple program in our $PATH, printargs:
.P
    $ cat /usr/bin/printargs
    #!/bin/sh
    printf '%s\\n' "$@"
.P
Which just prints its arguments:
.P
    $ printargs a b c
    a
    b
    c
.P
We could do this:
.P
    $ printf '%s\\n' -f --flag --option '? foo bar *' > "$HOME"/.printargsrc
.P
    $ apf "$HOME"/.printargsrc printargs a b c
    -f
    --flag
    --option
    ? foo bar *
    a
    b
    c
.P
We could then make a permanent wrapper script in two lines:
.P
    $ cat >~/.local/bin/printargs
    #!/bin/sh
    exec apf "$HOME"/.printargsrc /usr/bin/printargs
    ^D
    $ chmod +x ~/.local/bin/printargs
.P
Or just a shell function, if it's only wanted for interactive shells:
.P
    $ printargs() { apf "$HOME"/.printargsrc printargs "$@" ; }
.P
It's not considered an error if the file doesn't exist or is empty. If it's a
directory or otherwise not byte-readable, an error will be printed to stderr,
but execution of the called program will continue anyway. Blank lines or lines
beginning with # are also ignored. Both leading and trailing whitespace is
preserved.
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>