-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.py
51 lines (43 loc) · 1.5 KB
/
tmux.py
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
from os import chdir, cpu_count
from subprocess import call
from argparse import ArgumentParser
from shutil import rmtree
from pathlib import Path
import apt
tmux_install_dir = Path.home() / ".local"
tmux_dir = Path.home() / "tmux"
apt_cache = apt.Cache()
nproc = str(cpu_count())
build_tag = "3.4"
parser = ArgumentParser(description='Build the tmux program')
packages_for_build = [
"make",
"bison",
"libevent-dev",
]
parser.add_argument('-b', '--build', action='store_true', help='Download/Update sources and build/install')
parser.add_argument('-c', '--clean', action='store_true', help='Clean before build')
args = parser.parse_args()
chdir(Path.home())
# Install packages only if needed
for pac in packages_for_build:
if not apt_cache[pac].is_installed:
print("Needs to install packages for building konsole")
call(["sudo", "apt-get", "install", "-y", *packages_for_build])
break
if args.clean:
if tmux_dir.exists():
rmtree(tmux_dir)
if args.build:
if not tmux_dir.exists():
call(["git", "clone", "-b", build_tag, "https://github.com/tmux/tmux.git", tmux_dir])
else:
call(["git", "-C", tmux_dir, "pull"])
call(["git", "-C", tmux_dir, "checkout", build_tag])
chdir(tmux_dir)
call(["sh", "autogen.sh"])
call(["./configure", "--prefix={}".format(tmux_install_dir)])
call(["make", "-j", nproc])
if apt_cache["tmux"].is_installed:
call(["sudo", "apt-get", "remove", "-y", "tmux"])
call(["make", "install"])