@@ -39,6 +39,38 @@ function win_start
3939 end
4040end
4141
42+ function win_autostop
43+ # Check if container is running
44+ if not docker ps --format ' {{.Names}}' | grep -q ' ^windows$'
45+ return 0
46+ end
47+
48+ set -l state_file ~/.cache/win_last_active
49+
50+ # Check for active xfreerdp processes
51+ if pgrep -x xfreerdp3 > /dev/null
52+ # Active sessions - update timestamp
53+ touch $state_file
54+ echo " Active Windows sessions detected, keeping running."
55+ else
56+ # No active sessions - check idle time
57+ if test -f $state_file
58+ # Check if file is older than 10 minutes
59+ if string length -q -- (find $state_file -mmin +10 -print -quit )
60+ echo " No active Windows sessions for 10 minutes, stopping..."
61+ win_stop
62+ rm -f $state_file
63+ else
64+ echo " No active Windows sessions, but within idle timeout."
65+ end
66+ else
67+ # Create initial timestamp
68+ touch $state_file
69+ echo " No active Windows sessions, starting idle timer."
70+ end
71+ end
72+ end
73+
4274function win_stop
4375 echo " Stopping windows..."
4476 pkill xfreerdp3 2> /dev/null
@@ -52,7 +84,7 @@ function win_windows -a class
5284 | sort -k2 -r
5385end
5486
55- function win -a app_path
87+ function win_app -a app_path
5688 # Ensure WinBoat container is running
5789 win_start
5890 or return 1
@@ -143,4 +175,51 @@ function win -a app_path
143175 return 1
144176end
145177
146- win $argv
178+ function win_help
179+ echo "Usage: win [OPTIONS] [APP]"
180+ echo ""
181+ echo "Launch Windows desktop or applications via RDP"
182+ echo ""
183+ echo "Options:"
184+ echo " --start Start Windows container"
185+ echo " --stop Stop Windows container and kill all RDP sessions"
186+ echo " --autostop Check and auto-stop if idle for 10 minutes"
187+ echo " --help, -h Show this help message"
188+ echo ""
189+ echo "Examples:"
190+ echo " win # Launch Windows desktop"
191+ echo " win pwsh # Launch PowerShell"
192+ echo " win ' C:\\ Program Files\\ App\\ app.exe' # Launch custom app"
193+ echo " win --start # Just start the container"
194+ echo " win --stop # Stop container"
195+ end
196+
197+ function main
198+ argparse -n win h/help start stop autostop -- $argv
199+ or return 1
200+
201+ if set -q _flag_help
202+ win_help
203+ return 0
204+ end
205+
206+ if set -q _flag_start
207+ win_start
208+ return
209+ end
210+
211+ if set -q _flag_stop
212+ win_stop
213+ return
214+ end
215+
216+ if set -q _flag_autostop
217+ win_autostop
218+ return
219+ end
220+
221+ # If no flags, launch app (or desktop if no app specified)
222+ win_app $argv
223+ end
224+
225+ main $argv
0 commit comments