raylu 7 ماه پیش
والد
کامیت
8f8f569e6e
2فایلهای تغییر یافته به همراه39 افزوده شده و 9 حذف شده
  1. 1 0
      .gitignore
  2. 38 9
      install_extras.py

+ 1 - 0
.gitignore

@@ -4,6 +4,7 @@
 /dust
 /eza
 /git-whence
+/jj
 /lazygit
 /oh-my-posh
 /starship

+ 38 - 9
install_extras.py

@@ -19,6 +19,7 @@ def main():
 	dust()
 	eza()
 	git_whence()
+	jujutsu()
 	lazygit()
 	oh_my_posh()
 	starship()
@@ -32,7 +33,7 @@ def bat():
 		assert platform.system() == 'Linux'
 
 	if subprocess.run(['dpkg', '-l', 'bat'], stdout=subprocess.DEVNULL).returncode == 0:
-		print('bat package already installed')
+		print_gray('bat package already installed')
 		return
 
 	subprocess.run(['sudo', 'apt', 'install', 'bat', '--yes'], check=True)
@@ -46,7 +47,7 @@ def delta():
 		assert platform.system() == 'Linux'
 
 	if subprocess.run(['dpkg', '-l', 'git-delta'], stdout=subprocess.DEVNULL).returncode == 0:
-		print('git-delta package already installed')
+		print_gray('git-delta package already installed')
 		return
 
 	client = httpx.Client()
@@ -75,7 +76,7 @@ def dua():
 
 	dua_path = CURRENT_DIR / 'dua'
 	if dua_path.exists():
-		print('dua already downloaded')
+		print_gray('dua already downloaded')
 		return
 
 	client = httpx.Client()
@@ -102,7 +103,7 @@ def dust():
 
 	dust_path = CURRENT_DIR / 'dust'
 	if dust_path.exists():
-		print('dust already downloaded')
+		print_gray('dust already downloaded')
 		return
 
 	client = httpx.Client()
@@ -128,7 +129,7 @@ def eza():
 		assert platform.system() == 'Linux'
 
 	if (CURRENT_DIR / 'eza').exists():
-		print('eza already downloaded')
+		print_gray('eza already downloaded')
 		return
 
 	client = httpx.Client()
@@ -148,7 +149,7 @@ def git_whence():
 		assert platform.system() == 'Linux'
 
 	if (CURRENT_DIR / 'git-whence').exists():
-		print('git-whence already downloaded')
+		print_gray('git-whence already downloaded')
 		return
 
 	client = httpx.Client()
@@ -156,9 +157,32 @@ def git_whence():
 	download(client, url, CURRENT_DIR / 'git-whence')
 	os.chmod(CURRENT_DIR / 'git-whence', 0o755)
 
+def jujutsu():
+	if platform.system() == 'Darwin':
+		print('$ brew install jj')
+		subprocess.run(['brew', 'install', 'jj'], check=True)
+		return
+	else:
+		assert platform.system() == 'Linux'
+
+	if (CURRENT_DIR / 'jj').exists():
+		print_gray('jj already downloaded')
+		return
+
+	client = httpx.Client()
+	latest = gh_latest_version(client, 'jj-vcs', 'jj')
+	version = latest['name']
+	arch = platform.machine()
+	url = f'https://github.com/jj-vcs/jj/releases/download/{version}/jj-{version}-{arch}-unknown-linux-musl.tar.gz'
+	tarball_path = CURRENT_DIR / 'jj.tar.gz'
+	download(client, url, tarball_path)
+	with tarfile.open(tarball_path, 'r:gz') as tar:
+		tar.extract('./jj', CURRENT_DIR, filter='data')
+	tarball_path.unlink()
+
 def lazygit():
 	if (CURRENT_DIR / 'lazygit').exists():
-		print('lazygit package already installed')
+		print_gray('lazygit package already installed')
 		return
 
 	client = httpx.Client()
@@ -182,7 +206,7 @@ def oh_my_posh():
 		assert platform.system() == 'Linux'
 
 	if (CURRENT_DIR / 'oh-my-posh').exists():
-		print('oh-my-posh already downloaded')
+		print_gray('oh-my-posh already downloaded')
 		return
 
 	client = httpx.Client()
@@ -204,7 +228,7 @@ def starship():
 		assert platform.system() == 'Linux'
 
 	if (CURRENT_DIR / 'starship').exists():
-		print('starship already downloaded')
+		print_gray('starship already downloaded')
 		return
 
 	client = httpx.Client()
@@ -238,5 +262,10 @@ def download(client: httpx.Client, url: str, path: pathlib.Path) -> None:
 			for chunk in r.iter_bytes():
 				f.write(chunk)
 
+def print_gray(*args: object):
+	print('\x1B[90;m', end='')
+	print(*args, end='')
+	print('\x1B[0m')
+
 if __name__ == '__main__':
 	main()