I'm trying to do a fancy-shmancy tweak in my Tiny Core Linux command line. I decorated my PS1 like this:
http://i.stack.imgur.com/iEBx2.jpg
But here is what I get in most cases:
http://i.stack.imgur.com/FN4dv.png
If I press Tab or Up\Down to scroll history it prints new PS1 strings on top of previous. On the other hand when I press Enter to run a command it prints a new line and it's all OK.
I'm running the Almquist shell (ash, not bash).
Can I implement the next algorithm:
1. If the last key pressed was Enter, then... (do nothing)
2. Else if the last key pressed was another key, then... (position the text pointer one line up to redraw the previous PS1.)
I would implement this right inside the PS1 definition. But how can I get the last key pressed before some action (when the PS1 is printed) using only ash variables and commands?
Related
I would like to start a julia script by using the keyboard shortcut Ctrl+Shift+H.
When the script starts, the keys Ctrl and Shift may still be pressed (depending on how quickly I remove my fingers).
I would like to be sure that these two keys are released before executing the rest of the script. To do that I need to test if the key are pressed.
Note that triggering an event when the key are released would not be enough as the keys may not be pressed when the script starts.
I found several references to detect when a key is pressed in Julia but I did not find one to test if a key is currently pressed.
Do you know how I could do that?
Here is a minimal example of why I would like to do that.
You can find here a file in the cnee format which enables to write "azerty" in the window which has the focus. If you type the following command in a terminal, "azerty" is typed in it as expected:
cnee --replay -sp 0 -f ./recorded_macro.xnl
In order to write "azerty" in any window (not just terminals), I create a keyboard shortcut Ctrl+Shift+H which executes this command. If I use the shortcut, the keys Ctrl and Shift are likely to be pressed when the command is executed (except if I use the shortcut very quickly) and instead of typing "azerty", the window with the focus will get Ctrl+Shift+a, Ctrl+Shift+z, Ctrl+Shift+e, Ctrl+Shift+r, Ctrl+Shift+t and Ctrl+Shift+y which will trigger actions in the window but will not write "azerty".
So, I would like instead to start a python script with this shortcut which waits for Ctrl and Shift to be non-pressed before executing the cnee command. Note again that waiting for the keys to be released with a listener is not a solution as the keys Ctrl and Shift may not be pressed at the start of the python script if I use the shortcut quickly (and so I will have to press again Ctrl and Shift before executing the cnee command which I do not want).
The following Gtk program will detect the release of shift, control, and alt that are already pressed before the program starts or gets the focus. Note that my keyboard at least seems to not always detect multiple keystrokes, so perhaps depending on your keyboard you may have to just detect one of those releases.
using Gtk
function keypresswindow()
txt = "Press and Release a Key"
state = ""
win = GtkWindow("Key Release Test", 500, 30) |> (GtkFrame() |> ((vbox = GtkBox(:v)) |> (lab = GtkLabel(txt))))
function keyreleasecall(w, event)
event.keyval == 65505 && (state *= "SHIFT ")
event.keyval == 65507 && (state *= "CONTROL ")
event.keyval == 65513 && (state *= "ALT ")
set_gtk_property!(lab, :label, "You have released: $state")
end
signal_connect(keyreleasecall, win, "key-release-event")
cond = Condition()
endit(w) = notify(cond)
signal_connect(endit, win, :destroy)
showall(win)
wait(cond)
end
keypresswindow()
I am using Sublime to work with R via Repl, all works fine...
But I wonder if its possible run commands lines from cursor until the begin of script without select lines above the cursor...
Because when I select lines above the cursor to run script, the cursor dont back to my last place that I was working and sometimes its dificult find my last place to continue with my work...
I am not expert programer and probably I miss a lot of tips to do it.
Below the cursor exist other command lines that I dont wanna run:
rm(list=ls())
library(dplyr)
library(readxl)
library(rtf)
library(ggplot2)
library(data.table)
df=mtcars
View(df)
| #Cursor here, only run codes above it
str(df)
summary(df)
names(df)
To select the lines, hold down Shift and either use ↑ to select all the above lines, or simply click at the beginning with your mouse. The keyboard shortcut Ctrl,, S (hit Ctrl+comma, release, and hit S) will eval the selection in SublimeREPL. Once you switch back to your code with the selection, simply hit → (right arrow) and your cursor will be back where it was at the end of the selection.
To answer your question: No, there is no way to evaluate all the content above your cursor in a REPL via a command or keyboard shortcut. You can evaluate the whole file, the current line, the current selection, or the current block of code.
I have recently run into the following use case in LightTable:
I want to execute a command (for instance, duplicate a line)
I press "Ctrl-Space" and a list of commands shows up
I select the command I need
I want to repeat this command often, but there is no keybinding for this command
I go to user.keymap where I am supposed to add a line like [:editor "alt-shift-w" :editor.watch.unwatch]
But I have no idea what is the :editor.watch.unwatch-like key for the command I have just found. All I know is the displayed name of this command: Editor: duplicate line
Is there a way to add this keybinding without digging up the documentation and finding the key?
If you add the beginning of a line like this to your user.keymap:
[:editor "alt-shift-w"
and position the keyboard cursor at the end of the line you should be able to type duplicate line and the relevant command should be listed in a popup autocomplete menu.
My Zsh prompt cursor is sometimes (most of the time actually) a line below were it should be (attaching screenshot):
If I hit enter multiple times, the prompt seems to get fixed:
My first thought is that it was an error within my custom prompt, so I replaced by prompt with a simple one containing only one digit:
PROMPT='> '
But the error persisted.
Any clues about what can be missing?
You can find my theme here: http://pastebin.com/cSJwGWKZ.
Notice that I'm using Oh My Zsh.
EDIT: The prompt seems to get fixed when I reach the bottom of the terminal (by hitting enters).
The culprit is %{$(echotc DO 1)%} in your RPROMPT, which moves the cursor one line down when printing RPROMPT. When reaching the bottom of your terminal there is no additional line to go down to, so the cursor just remains where it was.
Depending on where you want your RPROMPT you have basically two options:
On the same line as your input cursor (after λ):
Just remove %{$(echotc DO 1)%} from your RPROMPT:
RPROMPT='$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%'
One line (or any other number of lines, really) above your input:
Add %{$(echotc UP 1)%} at the beginning of your RPROMPT, this will move the cursor up one line, print the right prompt and move back down one line:
RPROMPT='%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'`
Note: the second method may lead to RPROMPT overwriting parts of PROMPT if both get to long and/or the terminal window to narrow. If RPROMPT remains on the same line as input, it will be hidden once the input reaches it (and will reapper if you delete some of the input).
I would like to retrieve the previous command in my R console that started with a certain character. For example, i can just press the up key to get the last command. However, I'd like the last command that started with xyz for example. Is there a way to do this?
if you're on a linux distro, you can press ctrl+R and start typing, and then ctrl+R to toggle through search matches.
you can also do, history(pattern="^xyz"), but this would require an additional copy.