Run text editor with Groovy such as VIM or Nano - groovy

We are using groovy to build our java applications. The goal of the groovy script is to checkout from SVN, run MVN, download release notes from Jira, allow user to edit release notes, then upload everything to S3 for public consumption.
My question comes in on the editing of the release notes. I would like to have groovy run vim on a txt file and allow the user to edit the file and quit vim. On vim exit I would like the script to continue along. This should run on a headless linux server. I have it working locally on my mac using the open command but we are moving our builds to a central AWS linux server.
Something like this is what I'm looking for:
println "Downloading release notes..."
"vi RELEASE-NOTES.txt".execute().waitFor()
println "Uploading the edited release notes here"
FWIW the solution I am using on Mac OS is:
"open -eW RELEASE-NOTES.txt".execute().waitFor();
It opens TextEdit, allows me to edit and save the file, on quitting TextEdit the app moves on and uploads my edited file.

I think the VI solution fails because you no longer have a console (but you weren't very specific about this).
I'm embarassed to say I don't know how to fix this on a Unix machine, on DOS I would use "command /c vi" to run it in a new command shell, but even then it might be a trick to give that shell a "Console" for you to input in (in windows it would open up a new window).
Something like what you said MIGHT work if you piped the user input/output to the app stdin/out, but I bet some linux guru knows a better way.
Problem is that "Groovy" owns the console allocated to user I/O. If you could put groovy in the background (equivilent of ctrl-z) or switch to another console (perhaps using Screen or Linux's multiple consoles) you might be able to pull it off, but I probably wouldn't try it myself.
Redirecting I/O might be a better bet, or just go find a non-gui text editor written in Java and integrate it (Might be your best bet).

It doesn't seem possible, as per this answer, because java's way of handling processes is just piping streams of bytes, which doesn't relate to piping video/tty/whatever. A possible solution is to open a new window with xterm. Since you are on a headless linux, i'm not sure this will work. Are you connecting via SSH? What about trying connect to the server using ssh -X and then run the command? (Or does the "headless" implies the minus X doesn't work? :-) )
println "Downloading release notes..."
['xterm', '-e', 'vi RELEASE_NOTES.txt'].execute().waitFor()
println "Uploading the edited release notes here"
And... have you thought about writing such a script in shell? Seems a bit more suited, IMO.
I think #Bill K's suggestion would be great, but after a quick googling i couldn't found any java CLI editor.

Related

Is there a way to see what a .cgi file contains scripting wise?

I work with remotely installed cameras that have a linux build installed in them. Our previous models allowed us to use SSH and run simple commands within their terminal to focus the image, reboot, factory default and the such without having to go to the remote location. We have swapped to a new kind of camera that still has a linux build inside but the previous commands are not as easily accessible if at all. These new cameras have a simple website that can do these actions instead but this can - and has - go wrong with a need for the SSH solution.
There is no way to directly access the camera (that I know of), all of this is through a cat6. I checked the source for the simple website trying to see what the focus button actually runs onclick and found its javascript refers to "/cgi-bin/focus.cgi" (I can provide the chunk of code if needed). I am familiar with programming but not to any pro degree and much less web development but I figure that .cgi might be my ticket to finding out how to activate this stuff from the linux terminal.
I tried making a python script to see if I could read the file in plain text or something but that's a no go. Don't know the first thing about web dev so if there is a neat tech way to open the server on the camera to pick its brains I don't know what it is and don't know where to start. Currently bouncing around all the directories in the camera trying to find some kind of command or clue to where the camera functions are. Double tab doesn't seem to have the commands I'm looking for, and they didn't include a manual with man command. I'm completely lost.

kdevelop detect concurrent file opens

My favorite editor, geany, has an option "Disk check timeout", after this timeout it checks if someone else has overwritten the file that I'm editing. This is a simple tool to detect if two people work on the same file (we don't use a version control system). Is there an option or a plugin for kdevelop that does the same thing?
Edit: as Zhigalin said KDevelop does the check automatically but only for local files, I need it for files opened using sftp.
In KDevelop this check is always active, you will get a popup as soon as you focus on that file in the editor.
Edit: if you are speaking of remote files than the reply is no, there is no such functionality.
So you have 4 options:
File a proposal here (which probably won't get implemented soon because of few active developers)
Patches are always welcome
[suggested] Start using a version control system like Git, there are even tools to automatically deploy on server when you make commit on a specific branch.
Use AutoFS(FUSE) to mount your server as a local folder.

Workflow: Working with git and sandbox on linux

I'am a linux users and web developer.
Actually I'm using KDE as desktop environment and Kate as IDE.
I'm working for a company and we're using remote sandbox for development.
This is my actual workflow:
Connect to remote sandbox via sftp using Dolphin (file Manager)
Open the file that I want edit and save it
Show the changes in the browser
When I've finish I must copy the file that I've edited from remote to my git local folder and commit changes.
In the past I've used SublimeText with "upload on save" plugin, but I can't actually with Kate.
Is there a better workflow with Linux and Kate (or similar) editors?
Thanks you
In my experience with this setup, the fastest way to work will be to have Konsole (or preferred shell application) open with an SSH connection to the sandbox. Git must be installed on the sandbox for this to work.
Alternatively, you can mount to the filesystem and manage the repository directly from your operating system, but I've found this to be unacceptably slow relative to the size of the repository. Moreover, there's something magical about the way Dolphin mounts to remote filesystems using virtual folders that I could never figure out how to navigate to in a shell. I ended up going back to gvfs so that I had a clear path.
Lastly, Kate is not an IDE - it's just an editor. Not knocking it, it's actually my editor of choice in which I spend half of my life looking at, so you've got a friend in me :) Nevertheless, I'm not aware of a git plug-in for it, but depending on personal preference, I'd bet you're never going to beat the git core console app.

Automated Context Switching Between Projects via SSH and Multiple Terminals

I'm looking for some guidance on an approach to automate the process of quickly switching between projects.
Putty Windows (2 of them):
Vim with project.session open (multiple tabs)
IPython open to the working directory of the project
What I want to automate in its respective windows:
Save all files, save session, close vim, change working directory of vim to next project, open related project session.
Close ipython (as I often restart it during development and want a fresh instance), change directory to next project'ss location, open a new ipython
A magic solution would be a single command that would change the state of both putty windows. However, since I have no idea how that would be done my current approach would be:
Attempt to figure out how to bind all that Vim stuff to a key press or a custom vim script that is used like: :SwitchProj "projectName"
Write a bash script or find a bash command that will allow me to type as little as possible to perform the directory switch and open new ipython interpreter.
As I have very little experience on Linux and SSH I would be interested to know how other's have solved this problem or would approach it!
I believe that the Linux screen command should satisfy you. Google gives you many tutorials, like this one.
I sadly confess that I am not very familiar with screen. Learning it is in my todo list
If you use the Gnu Emacs editor, you can also open many shell buffers inside (and other interactive buffers, like gdb sessions, compilations, grep search) and edit many files. I do that very often. You can use emacs thru a tty interface, such as provided by ssh.
You could also use ssh with e.g. -X to also redirect X11 windowing. For you, that means that you'll need to run an X11 server on your local Windows machine.

Compatibility of x-www-browser

I want to open html files from a shell script. I know that Ubuntu has a command x-www-browser that will open the default browser on the system. I also found via some Googling that the command is part of the debian system. I was wondering if the command is available on non debian based distros. If it isn't is there a standard way of opening an html file in the default browser on a linux OS via command line? Note that I'm using Bash.
If you are wanting to open an HTML file that is local (and maybe even remote, I'd have to check), you can use xdg-open. This is the rough equivalent to "double-clicking" on a file to open it, so it's not limited to html files. Since you want to always open in the user's default browser, this would be the same as if they just opened it themselves.
Of course, if they have their system set up to have HTML files open in a text editor (like I did for awhile), this would backfire. But that's pretty rare.
Quick update
I just checked and xdg-open http://google.com brought up Google in Firefox (my default browser). So it does work for non-local files.
You could use xdg-open.

Resources