Customizing zsh auto complete - linux

I decided to give zsh a try. First i'll describe how things work right now and then i'll describe how I would like them to work.
Lets say I have 2 subfolders in current folder, 1st one "Documents", 2nd one "Downloads".
If I type "cd D" and press TAB, it will auto complete with "Do".
Press TAB again, it will auto complete with "Documents".
Press TAB again, it will auto complete with "Downloads".
Press TAB again, it will auto complete with "Documents" (I appreciate that here it dosen't go back to "Do" like Bash does).
At this point I have to pres Enter twice to change the directory. (first Enter to select "Documents" and second one to execute the comand).
How I would like zsh to behave:
If I type "cd D" and press TAB, I would like to auto complete with "Documents".
Press TAB again, should auto complete with "Downloads".
Press TAB again, should auto complete with "Documents".
Press Enter once and the directory should change to "Documents".
How can I do this? :-)

Wow, one year and no replies. I hope you found out how, but for others who might come across this via a search...
First make sure you have the completion module loaded with this line
zmodload zsh/complist
Then you can bind Enter, aka ^M, during menuselect to the function accept-line - which is normal behaviour - but by prefixing it with a dot, if forces it to leave menuselect mode before the function executes
bindkey -M menuselect '^M' .accept-line

Related

Windows 10 paste timestamp anywhere

I´d like to have a shortcut to place a timestamp at any program that I use in Windows 10.
I didn't found any native resource for that.
I wonder if I could write some macro or script or some basic function that returns a timestamp, invoked by a shortcut, regardless of the current task that I´m working.
You can do it with powershell.
Create a shortcut with this command line:
powershell.exe -c "Get-Date | Set-Clipboard"
Each time you start the shortcut, the clipboard will get a new timestamp.
So I went to my desktop, right click on it, and used the command : New >> shortcut.
After right click on this new shortcut, and selected 'Properties'.
In the 'General' tab I put "NOW CTRL + ALT + bar" in the first field (that´s the sortcut´s name).
In the 'Shortcut' tab I put the command above in the first field,
and "CTRL + Alt + /" in the third field.

Decorate a block of text with a digraph box

Is there a vim scrip to allow me to visually select a box, then put a box around it using digraphs?
For example, input:
Hello World
And the output after visual selection (and the calling the script)
┌─────────────┐
│ Hello world │
└─────────────┘
Thanks!
Interesting... I had to do a lot of those re-formatting, thus I wrote a script called "BlockIt", do exactly what you want I guess. And it can do more than that.
Check it out:
https://github.com/sk1418/blockit
Not tested but DrawIt (command \b) should do that.
Look at www.vim.org for other drawing scripts (link to my search results).
You can use visual block mode for this purpose.
Press Ctrl+V to enter visual mode.
Move arrows left, right, up and down to select your box. (If you wanted to interchange the ends, you can press Ctrl+O. I mean, we usually select through the bottom right end. If you want to switch to top left corner and select topside, you can use this)
Now, after making the selection to fit your desired box size, you can fill it with a character like #,* or whatever you want.
Press r# to replace the entire box with a #. You can put any character after r.
Now, your box is full of characters.
You want to type something inside! You can enter replace mode by pressing Insert twice.
Then, start typing your text . press Esc once done.

What does ccw do in Vim macro

In the following vim macro from this article, the author gives an explanation. I understand some but not everything.
:qccwcommand<Esc>:w<Ctl-W>jj<Enter>q
This macro (which includes the record start / stop, if you’re wondering) will change the current ‘path_to_command’ word to ‘command’, write the file out to disk, change window splits to the grep search results, move down one line in the results and navigate to that result’s location.
Q1. What is ccw doing here? Is it something to do with cw (change word) but I am not sure.
Q2. :w must be to write, right?.
Q3. What is <Ctrl-W>jj doing here? The following is what :h CTRL-W_J is about but I am not sure if I am looking into the correct help nor the meaning of the help in this context.
*CTRL-W_J*
CTRL-W J Move the current window to be at the very bottom, using the
full width of the screen. This works like closing the current
window and then creating another one with ":botright split",
except that the current window contents is used for the new
window.
you're confused because ccw taken literally in that sequence of commands dosen't really make sense!
the initial qc means "start macro recording in register c"
then the next cw means change word (e.g. delete the next word and leave editor in insert mode)
also notice that the final command is a q: this means to finish the macro recording. Macros are super useful when doing things that require a lot of repetition!!1 --> http://vim.wikia.com/wiki/Macros
then, his explanation in the blog post contains the answer to Q2 and Q3
This macro (which includes the record start / stop, if you’re wondering)
will change the current ‘path_to_command’ word to ‘command’, write the file
out to disk, change window splits to the grep search results, move down one
line in the results and navigate to that result’s location. I ran the macro
by hitting #c and then verifying the line selected was one that I wanted to
change. For a few instances where I did not want to change the line, I
manually navigated to the next search result and then re-ran the #c macro.
Q2 - yup, to save the file: "write the file out to disk"
Q3 - the <Ctl-W>jj<Enter> is a sequence of Vim key commands to move to the next entry in the quickfix window from the vimgrep, as he indicates: "write the file
out to disk, change window splits to the grep search results, move down one
line in the results and navigate to that result’s location."

Linux command line issue with prompt

I started to manage a new server based on CentOS. I wanted to change the prompt, so I wrote the following command :
PS1="\e[0;36m[`pwd`]\$\e[m "
It worked perfectly. But since I got an annoying issue. When I write something quite long, or displays an older command that is quite long using up arrow, or paste it, and then click on "home" to get to the top of the line, the cursor stops within the command, 10 characters ahead of the prompt. For example, lets say I write this :
[/]$ git log --pretty=oneline
And then click on home button, the cursor will stop on the "p" letter, after "--". And if I try to move with left key to get on top of the line, it does that annoying bip saying "you are already there, mate"...
Now, lets say I wrote
ls
and right after
git log --pretty=oneline
If I go up two times, the prompt displays this :
[/]$ git log --ls
And if I keep going up the "git log --" never goes away. Now if I press enter, it will still launch the ls command without any problem. Seems like it's just a display issue. But still, that confuse me all the time...
Thanks ahead for your help !
Use \w to print the working directory in your shell prompt, rather than trying to embed a command.
You also need to escape the escape sequences so that bash doesn't attempt to count them as printed characters. This is done by enclosing them with \[ and \].
So you should end up with something like:
PS1="\[\e[0;36m\][\w]\$\[\e[m\]"
Your prompt is also very compact, you may want to stick some spaces in it. The key is that you have used the brackets to escape the non-printable characters.
You can find a complete list of these substitutions in the PROMPTING section of the bash man page.

How to disable editing my history in bash

In bash, when I go back in history, edit some command and run it, this edited command is appended to history and the original one is left intact. But every once in a while I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. I can't put my finger on how this happens.
Can someone explain? My goal is to avoid this, so any edit to a previous command always gets appended to history and never replaces the original.
I somehow manage to affect the original command, i.e. my edit replaces the original command back in history.
Right. If you go back in your history and edit the line without pressing return to execute the command but instead moving to another history entry, you've just edited the history entry. If you then list your history, you will see a * on the line indicating that you edited it. I find this "feature" immensely frustrating. Others have provided good examples of how to reproduce this.
My goal is to avoid this, so any edit to a previous command always gets appended to history and never replaces the original.
I too wanted to disable it. I found the solution via this answer over on unix.stackexchange.
To summarize, you need to enable the revert-all-at-newline readline setting which is off by default. If the setting is on then bash will revert any changes you made to your history when you execute the next command.
To enable this setting in your shell, you should add the following to your ~/.inputrc file and then restart your shell:
$include /etc/inputrc
set revert-all-at-newline on
The first line is needed because I guess that if you supply your own .inputrc file the default /etc/inputrc file is not included which is probably not what you want.
If you go back to some previous command and edit it, but then DON'T execute it (instead using history commands to go to some other command and execute it), then the edits will remain there in your history list.
Pressing Ctrl + C, after editing, counters this behaviour. It leaves the original command in tact i.e. it cancels remembering edits to the original.
Here's my own answer, please correct or provide more details if you can.
When the "vi" option is set in bash ("set -o vi" -- "Use a vi-style command line editing interface"), there are two modes of editing a command from history.
The first mode (let's call it "basic") is when you start editing immediately using Backspace, Del and character keys.
The other mode is the "vi mode", entered when you hit Esc.
If you want to keep your history intact, DO NOT use both modes in the same edit. I don't know how bash works exactly, but you can think of it this way:
Entering the "vi mode" applies any changes done in "basic mode" to the original command, and creates a copy of the command that you can edit further using vi-style commands.
The changes get applied when you hit Enter (execute), Up, Down or j,k (move to another command in history).
The changes do not get applied if you hit Ctrl-C.
Using either basic or vi-style editing ALONE does not affect the original command in history.
What do
echo $HISTCONTROL
echo $HISTIGNORE
give you?
Edit:
I was able to reproduce behavior similar to what you've seen by following these steps:
At the shell prompt, enter:
echo abcd
echo efgh
Press up arrow twice, so "echo abcd" is shown
Press 1 to add that character at the end
Press escape to enter command mode
Press left arrow twice so the cursor is on the "c"
Press x to delete the "c"
Press enter
Now as you step back through history, you'll see a new entry at the end:
echo abd1
and the entry that previously had "echo abcd" will now look like this:
echo abcd1
This is one way, I'm sure there are others.

Resources