2024-04-26 19:58:35 +00:00
|
|
|
import os
|
|
|
|
|
2024-04-27 13:32:33 +00:00
|
|
|
from cd.project import Project
|
|
|
|
from cd.projects import Projects
|
2024-04-26 23:10:30 +00:00
|
|
|
from rwx import ps
|
|
|
|
|
2024-04-26 21:55:20 +00:00
|
|
|
COMMANDS_PREFIX = 'cd-'
|
|
|
|
|
2024-04-27 15:09:51 +00:00
|
|
|
projects = Projects(os.environ)
|
|
|
|
project = Project(projects)
|
2024-04-27 13:32:33 +00:00
|
|
|
|
2024-04-26 21:55:20 +00:00
|
|
|
|
2024-04-26 23:10:30 +00:00
|
|
|
def cd_clone_branch():
|
2024-04-28 16:36:34 +00:00
|
|
|
print(f'''\
|
|
|
|
{project.url}
|
|
|
|
↓
|
2024-04-28 16:40:31 +00:00
|
|
|
''', end=str(), flush=True)
|
2024-04-26 23:10:30 +00:00
|
|
|
ps.run('git',
|
|
|
|
'clone',
|
2024-04-27 13:32:33 +00:00
|
|
|
'--branch', project.branch,
|
2024-04-26 23:10:30 +00:00
|
|
|
'--',
|
2024-04-27 13:32:33 +00:00
|
|
|
project.url,
|
2024-04-28 16:48:01 +00:00
|
|
|
os.path.realpath(os.curdir),
|
2024-04-26 23:10:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-26 21:58:06 +00:00
|
|
|
def cd_list_environment():
|
2024-04-27 15:09:51 +00:00
|
|
|
for variable, value in sorted(os.environ.items()):
|
2024-04-26 22:06:41 +00:00
|
|
|
print(variable, '=', value)
|
2024-04-26 21:55:20 +00:00
|
|
|
|
2024-04-26 19:58:35 +00:00
|
|
|
|
2024-04-26 21:24:46 +00:00
|
|
|
def install_commands(path):
|
|
|
|
user = '/usr/local/bin'
|
2024-04-26 23:10:30 +00:00
|
|
|
for command in [
|
|
|
|
'clone-branch',
|
|
|
|
'list-environment',
|
|
|
|
]:
|
2024-04-28 11:00:18 +00:00
|
|
|
print(command)
|
2024-04-26 21:55:20 +00:00
|
|
|
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}'))
|