~darkxst/ubuntu/trusty/gjs/1.38.1

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
const Gio = imports.gi.Gio;
const Mainloop = imports.mainloop;

function cat(filename) {
    let f = Gio.file_new_for_path(filename);
    f.load_contents_async(null, function(f, res) {
        let contents;
        try {
            contents = f.load_contents_finish(res)[1];
        } catch (e) {
            log("*** ERROR: " + e.message);
            Mainloop.quit('');
            return;
        }
        print(contents);
        Mainloop.quit('');
    });

    Mainloop.run('');
}

if (ARGV.length != 1) {
    printerr("Usage: gio-cat.js filename");
} else {
    cat(ARGV[0]);
}