@@ -295,6 +295,7 @@ def setup_shell_aliases():
295295
296296 aliases = f"""
297297{ marker }
298+ export PATH="$HOME/.local/bin:$PATH"
298299alias repo='~/git'
299300alias hub='~/hub'
300301alias status='~/hub --status'
@@ -661,11 +662,9 @@ def setup_node():
661662 if not ask_yn ("Continue without hub connection?" , default = False ):
662663 sys .exit (1 )
663664
664- # Step 3: Fetch config from hub
665+ # Step 3: Fetch config from hub and identify this node
665666 print ()
666667 print_step (3 , total_steps , "Sync from hub" )
667- local_key = ask ("This node's alias" , hostname )
668- local_name = ask ("Display name" , hostname .capitalize ())
669668
670669 hub_config = None
671670 hub_projects = None
@@ -699,12 +698,44 @@ def setup_node():
699698 print_warn ("Could not fetch hub config — using defaults" )
700699 hub_config = {}
701700
702- # Build node config
701+ # Try to auto-detect this node from the hub's hosts list
703702 hosts = hub_config .get ('hosts' , {})
704- hosts [local_key ] = {
705- 'name' : local_name , 'ip' : '127.0.0.1' ,
706- 'user' : user , 'roles' : ['local' ],
707- }
703+ local_key = None
704+ local_name = None
705+
706+ if hosts :
707+ # Skip the hub's own local_host entry — we're looking for *this* machine
708+ hub_local = hub_config .get ('hub' , {}).get ('local_host' , '' )
709+ candidates = {k : v for k , v in hosts .items () if k != hub_local }
710+
711+ # Match by username first (most reliable), then hostname
712+ for key , info in candidates .items ():
713+ if info .get ('user' ) == user :
714+ local_key = key
715+ local_name = info .get ('name' , key )
716+ break
717+ if not local_key :
718+ for key , info in candidates .items ():
719+ if key == hostname or info .get ('name' , '' ).lower () == hostname .lower ():
720+ local_key = key
721+ local_name = info .get ('name' , key )
722+ break
723+
724+ if local_key :
725+ print_ok (f"Matched hub host: { local_key } — { local_name } ({ hosts [local_key ].get ('ip' , '?' )} , { user } )" )
726+ # Preserve the hub's entry but mark as local
727+ hub_entry = hosts [local_key ]
728+ hub_entry ['roles' ] = list (set (hub_entry .get ('roles' , [])) | {'local' })
729+ hub_entry ['ip' ] = '127.0.0.1'
730+ hub_entry ['user' ] = user
731+ else :
732+ print_warn ("Could not auto-detect this machine in hub's hosts" )
733+ local_key = ask ("This node's alias" , hostname )
734+ local_name = ask ("Display name" , hostname .capitalize ())
735+ hosts [local_key ] = {
736+ 'name' : local_name , 'ip' : '127.0.0.1' ,
737+ 'user' : user , 'roles' : ['local' ],
738+ }
708739
709740 config = {
710741 'hub' : {
0 commit comments