@@ -29,6 +29,7 @@ func Fetch(app common.AppController) ([]dao.Resource, error) {
2929
3030func GetShortcuts () []string {
3131 return []string {
32+ common .FormatSCHeader ("s" , "Shell" ),
3233 common .FormatSCHeader ("d" , "Describe" ),
3334 common .FormatSCHeader ("o" , "Open" ),
3435 common .FormatSCHeader ("a" , "Add" ),
@@ -44,6 +45,13 @@ func InputHandler(v *view.ResourceView, event *tcell.EventKey) *tcell.EventKey {
4445 return nil
4546 }
4647 switch event .Rune () {
48+ case 's' :
49+ // Shell
50+ id , err := v .GetSelectedID ()
51+ if err == nil {
52+ Shell (app , id )
53+ }
54+ return nil
4755 case 'o' :
4856 OpenAction (app , v )
4957 return nil
@@ -199,3 +207,42 @@ func Inspect(app common.AppController, id string) {
199207
200208 app .OpenInspector (inspect .NewTextInspector ("Describe volume" , subject , content , "json" ))
201209}
210+
211+ func Shell (app common.AppController , id string ) {
212+ app .StopAutoRefresh ()
213+ app .SetPaused (true )
214+
215+ defer func () {
216+ app .SetPaused (false )
217+ app .StartAutoRefresh ()
218+ }()
219+
220+ app .GetTviewApp ().Suspend (func () {
221+ defer func () {
222+ if r := recover (); r != nil {
223+ fmt .Printf ("Shell panic: %v\n " , r )
224+ }
225+ }()
226+
227+ fmt .Print ("\033 [H\033 [2J" )
228+ fmt .Printf ("Mounting volume %s in temporary alpine container...\n " , id )
229+
230+ // Create a temporary container that mounts the volume
231+ // We use sh as the shell
232+ cmd := exec .Command ("docker" , "run" , "--rm" , "-it" , "-v" , id + ":/data" , "-w" , "/data" , "alpine" , "sh" )
233+ cmd .Stdin = os .Stdin
234+ cmd .Stdout = os .Stdout
235+ cmd .Stderr = os .Stderr
236+
237+ if err := cmd .Run (); err != nil {
238+ fmt .Printf ("\n Error executing shell: %v\n " , err )
239+ fmt .Println ("Ensure 'alpine' image is available or that you have permission to run containers." )
240+ fmt .Println ("Press Enter to continue..." )
241+ fmt .Scanln ()
242+ }
243+ })
244+
245+ if app .GetScreen () != nil {
246+ app .GetScreen ().Sync ()
247+ }
248+ }
0 commit comments