summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 3b5751bf57d6ab5b00a0db724d3fdd2a1c79e2db (plain)
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
# Maintainer: 160R@protonmail.com
_pkgname=page
pkgname=${_pkgname}-git
pkgrel=1
pkgver=v2.3.5
pkgdesc='Advanced, fast pager powered by neovim and inspired by neovim-remote'
arch=('i686' 'x86_64')
url="https://github.com/I60R/page"
license=('MIT')
depends=('neovim' 'gcc-libs')
makedepends=('rust' 'cargo' 'git')
provides=('page')
conflicts=('page')
source=("git+https://github.com/I60R/page.git")
md5sums=('SKIP')


pkgver() {
    checkout_project_root
    git describe --tags --abbrev=0
}

prepare() {
    rustc_version=$([[ "$(rustc --version)" =~ rustc\ 1.([0-9]+).* ]] && echo "${BASH_REMATCH[1]}")

    (($rustc_version >= 40)) && return 0;

    # Set error color
    echo -e '\e[0;31m'
    echo 'Minimum supported rust version is 1.40.0, please update'
    echo ' * rustup way: `rustup update`'
    echo ' * pacman way: `pacman -Sy rust`'
    # Reset color
    echo -e '\e[0m'
    return 1
}

package() {
    checkout_project_root

    cargo build --release

    # Install binaries
    install -D -m755 "target/release/page" "$pkgdir/usr/bin/page"

    # Find last build directory where completions was generated
    completions_dir=$(find "target" -name "shell_completions" -type d -printf "%T+\t%p\n" | sort | awk 'NR==1{print $2}')

    # Install shell completions
    install -D -m644 "$completions_dir/_page" "$pkgdir/usr/share/zsh/site-functions/_page"
    install -D -m644 "$completions_dir/page.bash" "$pkgdir/usr/share/bash-completion/completions/page"
    install -D -m644 "$completions_dir/page.fish" "$pkgdir/usr/share/fish/completions/page.fish"

    # Install MIT license
    install -D -m644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# Ensures that current directory is root of repository
checkout_project_root() {
    cd "$srcdir"
    cd "$_pkgname" > /dev/null 2>&1 || cd ..
}