abo-abo / oremacs

My Emacs config
https://oremacs.com/
296 stars 33 forks source link

Start an interactive process from dired #27

Closed novoid closed 4 years ago

novoid commented 5 years ago

Hi,

This issue refers to https://oremacs.com/2015/01/04/dired-nohup/ which explains how external commands could be invoked from dired.

My question refers to the possibility to do this for external commands that require user input as well.

The example command that requires user input is from https://github.com/novoid/appendfilename/

Testing the python -i approach on Windows 10 where I configured cygwin for the shell:

  1. mark two text files in dired
  2. Enter ! and:

    C:/Python36/python.exe -i "c:/Users/karl.voit/src/appendfilename/appendfilename/__init__.py"
    • I had to change the backslashes to slashes because I got "no file(s) found" (cygwin).

Results in:

INFO     Add text to file name ...
         (abort with Ctrl-C; complete 50 words with TAB)

Please enter text: >>> Traceback (most recent call last):
  File "c:/Users/karl.voit/src/appendfilename/appendfilename/__init__.py ", line 387, in <module>
    main()
  File "c:/Users/karl.voit/src/appendfilename/appendfilename/__init__.py ", line 351, in main
    text = input('Please enter text: ').strip()
EOFError: EOF when reading a line

INFO     Add text to file name ...
         (abort with Ctrl-C; complete 50 words with TAB)

Please enter text: >>> Traceback (most recent call last):
  File "c:/Users/karl.voit/src/appendfilename/appendfilename/__init__.py ", line 387, in <module>
    main()
  File "c:/Users/karl.voit/src/appendfilename/appendfilename/__init__.py ", line 351, in main
    text = input('Please enter text: ').strip()
EOFError: EOF when reading a line

Testing the compile method: »"C-u M-x compile", then your script name«

  1. mark two text files in dired
  2. C-u M-x compile
  3. Enter

    make -k c:/Python36/python.exe ~/src/appendfilename/appendfilename/__init__.py

Results in:

-*- mode: compilation; default-directory: "~/2del/" -*-
Comint started at Mon Jul 15 13:30:14

c:/Python36/python.exe -i ~/src/appendfilename/appendfilename/__init__.py
C:\Python36\python.exe: can't open file '/cygdrive/c/Users/karl.voit/src/appendfilename/appendfilename/__init__.py': [Errno 2] No such file or directory

Comint exited abnormally with code 2 at Mon Jul 15 13:30:15
abo-abo commented 5 years ago

Hi,

The mentioned functionality is now in the orly package:

(define-key dired-mode-map "r" 'orly-start)

To test, open /usr/bin and press r on any executable.

Also works with this simple Python script:

#!/usr/bin/env python3

name = input("name: ")
print("Hello,", name)

The code detects if the file is executable and then runs it in comint.