Custom Input For Command Prompt? - windows

What I'm looking for seems to be very simple. I want to run a command prompt line, but have it to be easily editable for anyone to use. There are multiple commands to this script, but only one part needs to be changed, and asks the user for a custom input. I'm sure this is already online, however after looking for hours and finding nothing as I have no clue what it would even be called, this is my last resort. Any help would be appreciated as I'm not even quite sure how to describe this.

Your question is a bit vague but if I understand correctly it sounds like you are trying to read user input (ie. prompt the user for input) from a batch file. If so, this should work for you:
set /p CustomInput="Please enter blah blah blah.."
Then you can use %CustomInput% as a variable in the script.

I guess you may also add this line:
goto %CustomInput%

Related

Refreshing Bash prompt after invocation of a readline bound command

My shell is GNU Bash 4.3.11, and I currently have M-h bound to cd .. by calling the builtin
bind -x '"\eh": "cd .."'
This gives me a nifty way to navigate up the directory tree, as I can repeatedly hit M-h instead of the incredibly time-consuming cd ... It has the downside, however, either of not resetting my $PS1 or of not redrawing my prompt, so I lose the context of my current working directory until I enter a new command.
One alternative I'm aware of is to put a macro like
"\eh": "\C-a\C-kcd ..\C-m"
in my .inputrc directly. This, however, has the downside of not only losing the context of any existing command I'm typing in (which I think can probably be worked around) but also of printing out cd .. (which I don't think can be).
My desired behavior is to be able to be in a directory ~/one/two with prompt ~/one/two$; hit M-h; and then be in ~/one and have the prompt be ~/one$, ideally keeping any command I had initially. How can I achieve this?
Figured this out.
# maintain state
bind -x '"\200": TEMP_LINE=$READLINE_LINE; TEMP_POINT=$READLINE_POINT'
bind -x '"\201": READLINE_LINE=$TEMP_LINE; READLINE_POINT=$TEMP_POINT; unset TEMP_POINT; unset TEMP_LINE'
# "cd .." use case.
bind -x '"\206": "cd .."'
bind '"\eh":"\200\C-a\C-k\206\C-m\201"'
I'm quite late to that party - and came here looking for that answer also. First of all: As you were the only one providing information on this: thanks for not letting it come to this: https://xkcd.com/979/ ;) instead you pointed me to the on corner in that fractal that seems to hold a solution.
This approach, in my opinion backed up by hours of trying, is the only one where you can a) replace content on the line, and b) execute bash code. Let me offer up some more suggestions to a specific problem:
If you are trying to have it both ways: insert something on the command line, or executing code, things can get very tricky. for both, there exist bindings, and I let the reader figure out things with help bind. But in the case you e.g. have FZF produce some directory as output, and you'd either cd to it, or have it pasted into your command -- depending on the keystroke done in FZF -- things will get near impossible. you'll face either the not-updated-promt problem, or not be able to execute the cd command in the top shell (where it has effect).
Your solution would be a multiplexing -x binding, inspecting the output for "macros" (get extracted and eval'd) or the default pass-through (manipulating READLINE_LINE/POINT).
Because the solution has some enormity, and the audience may be limited (closed answer...), I'll leave it at a haphazard gist where I pasted my code which works now. To make up for the brevity and uncommented-ness, I welcome any questions in comment or elsewhere. Hope someone may be pointed in the right direction.
- The code related to this question starts in function bindInsertEvalWithMacrosVi
- It is designed for Vi keybindings but the same principles apply for normal readline mode
- It depends on some \C-x\C-... combinations to do redrawing in places that are not related to this post.
https://gist.github.com/simlei/032470cfcd23641987f97a96749128d7

Run command in cmd from Ruby

I know this is probably a really simple question, but I am having a really hard time finding a solution. I am working on windows in cmd. I am simply trying to use this command:
find /i \"chef_server_url\" C:/chef/client.rb
I know the command works. It simply returns a url in a file that I wanted to check.
I want to execute this in code and return the results in my code. But I am having a hard time formatting the string especially with the escape characters
I am using %x[] to do so. So ideally I would just say
%x[find /i \"chef_server_url\" C:/chef/client.rb]
But the c:/chef/client.rb will not format correctly because it thinks /c and /c are not supposed to be that way
Are you trying to access the Chef Server URL from inside Chef? You can use Chef::Config[:chef_server_url] but the deeper question is what you trying to do?
The short answer to your question is that there is more than one way to run a system command in ruby:
The Kernel#system method takes a plain string, so as long as you can get your command accurately represented in a string, it should work. Something like system 'find /i "chef_server_url" C:/chef/client.rb' should work.
Backticks will do similar, which should look something like this: find /i "chef_server_url" c:/chef/client.rb (wrap in `backticks`, I'm not sure how to format on StackExchange).
I'd first recommend getting a string representation of your command, puts it out, copy paste to a command window. If it works, then send it through system.
However, like others here, I suspect there is a better solution to the underlying problem you're trying to solve.
I'm not anywhere near a windows computer for testing, so you'll have to experiment with these.

modifying the bash prompt on mac

On my bash prompt, I would like to see just the name of the current directory followed by "$" in different colours.
So I used this code but when I have a long typed command, I see the cursor in different place than where the typing is taking place. How can this "hard to describe" problem be fixed? Thanks
PS1='\[\e[0;36m\]\W\[\e[m\]\[\e[1;31m\]\$\[\e[m\]'
Use a carriage-return after outputting the current directory, I've done this for years and it works a treat, something like:
if [ "$PS1" ]; then
PS1="\[\e[0;36m\]\W\n\[\e[m\]\[\e[1;31m\]\$\[\e[m\]"
fi
You always have your current directory (no matter how long) on top of your $ prompt.
I put other info up there as well like username, machine name and exact time and date. I colour them differently so they really stand out. Helps if you have multiple sessions going on, on different machines with or without root(!) privileges (have to be root when deploying a complete rebuild). And has saved the day many times when I need to know when I did something or other (ok, it's when that task ended - but still helps).
But most of all, it's great to know your current directory by simply looking at your command line prompt :) )
Don't know how other people work efficiently without it!

how do i make a batch program that types

hi i am interested in making a batch program that allows me to be able to place my cursor anywhere and have the batch program type for me as if i'm typing. i have looked at a lot of different sites for help but it might be it's impossible with batch programming or i just need someone on here to tell me how your input is much appreciated. i have tried to use echo >>etc .text commands but that only inserts input into that specific text document. I would like to know this because it would improve my batch programming and would be a valuable tool to have.
Ok, after a bit of thinking, the only way to do this is to update the clipboard with whatever you want to "type" into the program, and then press "Ctrl + V" to paste it. The way you would go about inmplementing this is up to you, but to place something in the clipboard via batch is:
Clip < file.txt
And you would have to make a batch file which would continuosly update the clipboard with whatever you wanted to paste. The way you do this is up to you.
Other then that, I dont see any other way you could do something like this in batch. Like I mentioned your better off doing this in C#.
Mona

Interact with console program via batch script

I want to start a console program via batch script. Starting the console program works fine. I am starting it via call xxx.exe para para. The problem is that the console program wants an input like that after it is started.
call xxx.exe para para
please type in password:_
Is it possible to make the input of the password from the batch script.
Whether you are using batch or bash, as it seemed originally, you could try this simple piping:
echo YourPassword| program.exe parameters...
Note that if it is indeed a batch script, it is vital to make sure there's no extra space between your password and the |, or it will be passed along with the password, as part of the password. In bash, if I'm not much mistaken, such a space would be disregarded (or maybe it would only be so if you enclosed the echoed string in quotation marks, I'm not entirely sure).
Anyway, the above doesn't always work, as some programs implement password reading in a way that disregards the input stream piped from another command.
You tagged your question "Windows" and "Batch" and asked about "batch" in the question. The answer to that question is: Yes, use set like this:
set /p password=please type in password:
If you're really asking about 'bash' shell, you should re-tag your question (and change the text).

Resources