easy-worktree 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
easy_worktree/__init__.py CHANGED
@@ -28,8 +28,16 @@ MESSAGES = {
28
28
  "ja": "使用方法: wt clone <repository_url>",
29
29
  },
30
30
  "usage_add": {
31
- "en": "Usage: wt add (ad) <work_name> [<base_branch>] [--no-setup] [--select]",
32
- "ja": "使用方法: wt add (ad) <作業名> [<base_branch>] [--no-setup] [--select]",
31
+ "en": "Usage: wt add (ad) <work_name> [<base_branch>] [--no-setup] [--select [<command>...]]",
32
+ "ja": "使用方法: wt add (ad) <作業名> [<base_branch>] [--no-setup] [--select [<コマンド>...]]",
33
+ },
34
+ "usage_select": {
35
+ "en": "Usage: wt select (sl) [<name>|-] [<command>...]",
36
+ "ja": "使用方法: wt select (sl) [<名前>|-] [<コマンド>...]",
37
+ },
38
+ "usage_run": {
39
+ "en": "Usage: wt run <name> <command>...",
40
+ "ja": "使用方法: wt run <名前> <コマンド>...",
33
41
  },
34
42
  "usage_rm": {"en": "Usage: wt rm <work_name>", "ja": "使用方法: wt rm <作業名>"},
35
43
  "base_not_found": {
@@ -864,15 +872,30 @@ def cmd_add(args: list[str]):
864
872
  clean_args = []
865
873
  skip_setup = False
866
874
  select = False
875
+ select_command = None
867
876
 
868
- for arg in args:
877
+ i = 0
878
+ while i < len(args):
879
+ arg = args[i]
869
880
  if arg in ["--skip-setup", "--no-setup"]:
870
881
  skip_setup = True
871
882
  elif arg == "--select":
872
883
  select = True
884
+ if i + 1 < len(args):
885
+ select_command = args[i+1:]
886
+ break # Consume everything after --select as command
873
887
  else:
874
888
  clean_args.append(arg)
875
-
889
+ i += 1
890
+
891
+ # Heuristic: if clean_args is empty but we have select_command,
892
+ # it likely means the user put --select before the work_name.
893
+ if not clean_args and select_command:
894
+ # Take the first one as work_name
895
+ clean_args.append(select_command.pop(0))
896
+ if not select_command:
897
+ select_command = None
898
+
876
899
  if not clean_args:
877
900
  print(msg("usage_add"), file=sys.stderr)
878
901
  sys.exit(1)
@@ -901,7 +924,7 @@ def cmd_add(args: list[str]):
901
924
  current_sel = "main" if p == resolved_base else p.name
902
925
  break
903
926
 
904
- switch_selection(work_name, base_dir, current_sel, last_sel_file)
927
+ switch_selection(work_name, base_dir, current_sel, last_sel_file, command=select_command)
905
928
 
906
929
 
907
930
  def cmd_stash(args: list[str]):
@@ -1504,6 +1527,7 @@ def cmd_select(args: list[str]):
1504
1527
  return
1505
1528
 
1506
1529
  target = args[0]
1530
+ command = args[1:] if len(args) > 1 else None
1507
1531
 
1508
1532
  if target == "-":
1509
1533
  if not last_sel_file.exists():
@@ -1518,7 +1542,46 @@ def cmd_select(args: list[str]):
1518
1542
  print(msg("error", msg("select_not_found", target)), file=sys.stderr)
1519
1543
  sys.exit(1)
1520
1544
 
1521
- switch_selection(target, base_dir, current_sel, last_sel_file)
1545
+ switch_selection(target, base_dir, current_sel, last_sel_file, command=command)
1546
+
1547
+
1548
+ def cmd_run(args: list[str]):
1549
+ """wt run <work_name> <command>... - Run command in worktree and exit"""
1550
+ if len(args) < 2:
1551
+ print(msg("usage_run"), file=sys.stderr)
1552
+ sys.exit(1)
1553
+
1554
+ work_name = args[0]
1555
+ command = args[1:]
1556
+
1557
+ base_dir = find_base_dir()
1558
+ if not base_dir:
1559
+ print(msg("error", msg("base_not_found")), file=sys.stderr)
1560
+ sys.exit(1)
1561
+
1562
+ # find target path
1563
+ target_path = base_dir
1564
+ if work_name != "main":
1565
+ config = load_config(base_dir)
1566
+ worktrees_dir_name = config.get("worktrees_dir", ".worktrees")
1567
+ target_path = base_dir / worktrees_dir_name / work_name
1568
+
1569
+ if not target_path.exists():
1570
+ print(msg("error", msg("select_not_found", work_name)), file=sys.stderr)
1571
+ sys.exit(1)
1572
+
1573
+ # set environment variables
1574
+ env = os.environ.copy()
1575
+ env["WT_SESSION_NAME"] = work_name
1576
+
1577
+ # run command
1578
+ try:
1579
+ subprocess.run(command, cwd=target_path, env=env, check=True)
1580
+ except subprocess.CalledProcessError as e:
1581
+ sys.exit(e.returncode)
1582
+ except Exception as e:
1583
+ print(msg("error", str(e)), file=sys.stderr)
1584
+ sys.exit(1)
1522
1585
 
1523
1586
 
1524
1587
  def cmd_current(args: list[str]):
@@ -1540,7 +1603,7 @@ def cmd_current(args: list[str]):
1540
1603
  print(name)
1541
1604
 
1542
1605
 
1543
- def switch_selection(target, base_dir, current_sel, last_sel_file):
1606
+ def switch_selection(target, base_dir, current_sel, last_sel_file, command: list[str] = None):
1544
1607
  """Switch selection and update last_selection"""
1545
1608
  # Calculate target path
1546
1609
  target_path = base_dir
@@ -1599,10 +1662,19 @@ def switch_selection(target, base_dir, current_sel, last_sel_file):
1599
1662
  if os.environ.get("TMUX"):
1600
1663
  subprocess.run(["tmux", "rename-window", f"wt:{target}"], check=False)
1601
1664
 
1602
- os.execl(shell, shell)
1665
+ if command:
1666
+ cmd_str = " ".join(command)
1667
+ # コマンド実行後にシェルを維持するために "cmd; exec shell" を実行
1668
+ os.execl(shell, shell, "-c", f"{cmd_str}; exec {shell}")
1669
+ else:
1670
+ os.execl(shell, shell)
1603
1671
  else:
1604
1672
  # Output path for script/backtick use
1605
1673
  print(str(target_path.absolute()))
1674
+ if command:
1675
+ # 非 TTY の場合でもコマンドがあれば実行しておく (パイプなどでの利用を想定)
1676
+ import subprocess
1677
+ subprocess.run(command, cwd=target_path, check=True)
1606
1678
 
1607
1679
 
1608
1680
  def cmd_setup(args: list[str]):
@@ -1944,7 +2016,7 @@ def show_help():
1944
2016
 
1945
2017
  def show_version():
1946
2018
  """Show version information"""
1947
- print("easy-worktree version 0.1.6")
2019
+ print("easy-worktree version 0.1.8")
1948
2020
 
1949
2021
 
1950
2022
  def main():
@@ -1991,6 +2063,8 @@ def main():
1991
2063
  cmd_current(args)
1992
2064
  elif command in ["co", "checkout"]:
1993
2065
  cmd_checkout(args)
2066
+ elif command == "run":
2067
+ cmd_run(args)
1994
2068
  else:
1995
2069
  # その他のコマンドは git worktree にパススルー
1996
2070
  cmd_passthrough([command] + args)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: easy-worktree
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: Git worktree を簡単に管理するための CLI ツール
5
5
  Project-URL: Homepage, https://github.com/igtm/easy-worktree
6
6
  Project-URL: Repository, https://github.com/igtm/easy-worktree
@@ -0,0 +1,6 @@
1
+ easy_worktree/__init__.py,sha256=47agzeavmQHhGxyYwVTG4JzPHzho4SUFXpadhuMM_qk,68504
2
+ easy_worktree-0.1.8.dist-info/METADATA,sha256=nEVPV5FiwfPj8K2A_96VA_dZ6-ZJ40nWA5bkq9BqNsA,6520
3
+ easy_worktree-0.1.8.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
4
+ easy_worktree-0.1.8.dist-info/entry_points.txt,sha256=Mf6MYDS2obZLvIJJFl-BbU8-SL0QGu5UWcC0FWnqtbg,42
5
+ easy_worktree-0.1.8.dist-info/licenses/LICENSE,sha256=7MGvWFDxXPqW2nrr9D7KHT0vWFiGwIUL5SQCj0IiAPc,1061
6
+ easy_worktree-0.1.8.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- easy_worktree/__init__.py,sha256=ubOIvRctUMf_OqG6Y0Vd7PMQ3jKDS_F8PeLM9GIi5ZY,65812
2
- easy_worktree-0.1.6.dist-info/METADATA,sha256=zicOjRw1QPuLUIL0kyU4FSvR-y0W6mnj3FF_F2jeoxU,6520
3
- easy_worktree-0.1.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
4
- easy_worktree-0.1.6.dist-info/entry_points.txt,sha256=Mf6MYDS2obZLvIJJFl-BbU8-SL0QGu5UWcC0FWnqtbg,42
5
- easy_worktree-0.1.6.dist-info/licenses/LICENSE,sha256=7MGvWFDxXPqW2nrr9D7KHT0vWFiGwIUL5SQCj0IiAPc,1061
6
- easy_worktree-0.1.6.dist-info/RECORD,,