Is it possible to add a -G option to ~/.ackrc - ack

When I do
ack -G "^.*$" "foo"
I get results... but when I put
-G "^.*$"
or
-G="^.*$"
or
-G
"^.*$"
in my `~/.ackrc/ I get no results... Does anyone know if -G can be used in ackrc?

It's a quoting problem. When executed on the command line:
$ ack -G="^.*$"
ack actually sees the following command line option (after quote processing by the shell)
-G=^.*$
without the quotes. Since the ~/.ackrc file is read without shell quote processing, place the above line without quotes into ~/.ackrc.
Update: That was only half of it. It looks like you need to use the following line in ~/.ackrc:
-G^.*$
I'm not completely sure why the = is not permitted there, but including it makes it part of the pattern, which is obviously not what you want.

You could alias ack to ack -G ?

Related

Sequence of keypresses crashes tmux

When I type C-b : to get to the command prompt, hitting escape and then quickly hitting any (or most) other key will cause tmux to indefinitely pause on the status bar. If you press enter, you can get back to tmux, but if you pres any two alphanumeric keys will cause the tmux server to crash. I have tried this on both set -g status-keys vi and set -g status-keys emacs as well as set -o vi and set -o emacs in bash. None of them seem to have an effect. I got my coworker to replicate this on his machine, so it doesn't seem like it's only me. What's up?
Seems to be fixed in the very newly released (11 hours ago) tmux 3.3!

Search and replace in multiple files using vim

Is it possible to apply the same search and replace in multiple files in vim? I'll give an example below.
I have multiple .txt files — sad1.txt until sad5.txt. To open them, I'll use vim sad* and it opened already. Now inside the 5 txt files they have similar word like happy999; I would like to change it to happy111. I am currently using this code:
argdo %s/happy999/happy111/gc | wq!
Eventually only the sad1.txt is changed. What should I do to run one script in the 5 txt files?
Use:
:set aw
:argdo %s/happy999/happy111/g
The first line sets auto-write mode, so when you switch between files, vim will write the file if it has changed.
The second line does your global search and replace.
Note that it doesn't use wq! since that exits. If you don't want to use auto-write, then you could use:
:argdo %s/happy999/happy111/g | w
This avoids terminating vim at the end of editing the first file.
Also consider looking on vi and vim for answers to questions about vi and vim.
That is a task for sed -i (-i for "in place", works only with GNU sed). Yet, if you really want to use vim or you do need the /c to confirm the replace, you can do it in two ways:
With some help from the shell:
for i in sad*.txt; do
vim -c ':%s/happy999/happy111/gc' -c ':wq' "$i"
done
(the /c will still work, and vim will ask for each confirmation)
Or with pure VIM
vim -c ':%s/happy999/happy111/gc' -c ':w' -c ':n' \
-c ':%s/happy999/happy111/gc' -c ':w' -c ':n' \
-c ':%s/happy999/happy111/gc' -c ':w' -c ':n' \
-c ':%s/happy999/happy111/gc' -c ':w' -c ':n' \
-c ':%s/happy999/happy111/gc' -c ':wq' sad*.txt
(In my humble opinion this last one looks horrible and repetitive and has no real advantages over the shell for, but it shows that pure vim can do it)
No doubt, argdo is great, but to type that much boilerplate becomes quite annoying over the time.
Give a try to far.vim. It's such a tool that provide many IDEs.
If you don't need/want to be prompted for confirmation on each search and replace, use the following command, after opening your files with vim sad*:
:argdo %s/happy999/happy111/g | update
You can find more info by looking at the documentation for argdo in vim (:h argdo) or here:
http://vim.wikia.com/wiki/Search_and_replace_in_multiple_buffers

ack results do not contain newlines in zsh

I use zsh as my default shell
When I do a simple ack command like
$ ack a_string
it does not insert a newline between the lines that match. So they all get jumbled up like
a_string is on this linethis is another line a_string is onand a third a_string line
Bash displays the results correctly:
a_string is on this line
this is another line a_string is on
and a third a_string line
zsh does not alias ack. Perhaps oh-my-zsh does that...
[...]
the easiest way to debug something like this is to:
See what is it that you are running as 'ack': which ack
Run zsh without loading any config file of yours, executing 'ack':
zsh -f -c 'cd test-dir && ack a_string'
You can also run which -a ack to see all "ack"s present in your path...

Alert in tmux when a process completes

Can I set tmux to trigger an alert in a non-active window when a process completes?
For example: I start a long build process. I would like to be notified when it completes, not each time it prints a status.
I'm surprised this answer hasn't been given yet: You can use the tmux window setting visual-bell for this. With bell-action you can then configure whether you want to see bells for the current window only, or for non-current window only (other). Personally I prefer the second, as you won't see noise generated by the shell, and you probably don't care about the notification if it's in the current window.
set-window-option -g visual-bell on
set-window-option -g bell-action other
When a process generates a bell, tmux will highlight the the title of the window that rings the bell as well as show a "Bell in window X" notification.
Then ring the bell at the end of the process. E.g.:
make; echo -e '\a'
(or && || instead of ; if you want to ring only on success or failure respectively)
There 3 solutions I know, none really ideal. You may put those commands in your ~/.tmux.conf or just run them directly as Tmux command via Ctrl-B :.
Monitor and alert whenever the output changes (you may then redirect output somewhere else so that output changes only after the command is complete):
:set -g visual-activity on
:setw -g monitor-activity on
Monitor and alert whenever the output did not change for a while (30 seconds here):
:set -g visual-silence on
:setw -g monitor-silence 30
(deprecated and someday replaced by a better option) Monitor and alert whevener the output contains a string matching given pattern (and possibly run your command like my-command; echo foobar):
:set -g visual-content on
:setw -g monitor-content foo*bar
$ some-command; tmux display-message "Task 1 done". However the message will only show for a short duration defined via :set -g display-time 4000.
If you keep the visual-* to off (default), it'll only highlight the name of the window in which the alert occurred without showing a global alert status message.
For details about each of these settings, see tmux man page
Updated (thanks for Steven Lu)
I finally found a solution that works for me. I use zsh for my shell, which has a feature called "Hook Functions" -- shell functions that execute on certain actions: http://zsh.sourceforge.net/Doc/Release/Functions.html.
It's likely other shells have a similar feature.
The hook function I use is precmd, which is executed each time the prompt is shown. ie, when a command has just finished running.
In my .zshrc:
precmd () {
echo -n -e "\a"
}
This sends a bell to tmux, which causes it to highlight just the window that the command was running in.
If you are already focused on that tmux window, this does nothing because the bell is immediately cleared.
The benefit of this approach is that it does not trigger on all visual activity. It only triggers when a command completes.
you can wrap your running script with a && bash derivative which will call a tmux command to notify you.
using && means you will only get notified when the script exits with error code 0. if you want it to notify you anyway, just use ;
as for the tmux commands to wrap the script, have a look at those bunch, they should suffice
select-window
split-window -h 'exec echo...'
send-keys
For future reference, people can also checkout the tmux-notify plugin, created by ChanderG, which was designed for this purpose.
Disclaimer: I'm a contributor to this plugin. Feel free to check it out and open an issue/pull request or feature request if you find a bug or see something that is missing.
there are two options:
set -g visual-activity on
setw -g monitor-activity on
have you tried setting them in your tmux.conf?
As a good workaround, you can use:
https://github.com/tcreech/tmux-notifications
You simply do:
$ command ; tmux-notify
You will get a nice notification in the status-bar (if enabled)
Building on #psp940's answer (where StackOverflow won't let me add a comment):
precmd () {
echo -n -e "\a" >$TTY
}
If you're using powerlevel10k's instant prompt feature, redirecting the bell directly to the terminal avoids a warning about pre-init console output. See also here.
Adding onto the answers from #wump and #psp940; I've found that the simplest way to be alerted any time a command completes is to put a bell in your PS1:
in tmux.conf
set-window-option -g visual-bell on
set-window-option -g bell-action other
In your .bashrc:
# ring bell every time a command completes
export PS1+=$'\[\a\]'
I'm not sure whether the += and $'' are bash-isms, but the principle will work in any shell.
The surrounding \[+\] tell your shell that the characters between them are zero-width

Is that a valid /usr/bin/sftp call?

I found this call in an app I started managing some time ago:
/usr/bin/sftp -b - -o Port=22 abc12#90.00.00.44
Whats suspicious is -b - -o ... isnt it? I think the param is missing here...
Thanks
I don't believe there's anything suspicious about it.
The -b - is simply reading the script from standard input which we can't tell from your sample where it's coming from. It may be redirected or it may just interact with the user. The - file name is quite prevalent at meaning standard input. Try cat - under Linux for example.
The sftp manpage states this clearly:
A batchfile of '-' may be used to indicate standard input.
The -o Port=22 is simply setting the SSH option to use port 22 (which is usually the default anyway).

Resources