I'm trying to get zsh to autocomplete a custom command.
The idea is that in my command foo:
foo --args #path/to/fi
all arguments with an "#" at the beginning should be autocompleted the same as regular files, keeping the "#".
So in the example above, when pressing <TAB> I would expect autocompletion to suggest file1.txt or file2.txt (or #path/to/file1.txt, #path/to/file2.txt), given these two files exist in the folder path/to, so I could autocomplete it to, for example:
foo --args #path/to/file1.txt
I've looked at the tutorial and the documentation, but can't quite get to grips with the syntax...
I expect I need something in:
_foo() {
# What to add here?
}
#compdef foo
I have a non-reg directory in which all performed test have a specific sub-directory named tc_TestName. In each of these subdirectories there is a log file call sim.log. I want to verify if the test is PASSED by searching for the string "TEST PASSED". So far I have performed the command
grep -rni --include "sim.log" "TEST PASSED" >& test_passed.txt
I am perfectly happy with the result, but since the sim.log files may be very big and I have more than 1000 tests, it takes quite a while to perform.
Is there any way to perform the search of the string "TEST PASSED" only on the last, let's say, 100 lines of my sim.log files ?
Many thanks in advance
As Apple's Official Doc said:
-viewDidUnload is deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.
Meanwhile, it's better to remove all -viewDidUnload implements from projects that the deployment target is iOS 6.0 or later. But removing it one by one is boring, especially you've hundreds of controllers & several projects.
So, is there any script or command that can do this batch job?
I figured out a command for Vim, I'm sure it'll make your life easier. ;)
Open Vim in desired root dir (generally, it'll be your root dir of your all controller files), press Shift : to enter command-line mode, run the command below:
:args **/*.m | argdo %s/^-\ (void)viewDidUnload\_.\{-}}\n^$\n//ge | update
This will replace all
- (void)viewDidUnload
{
[super viewDidUnload];
...
}
// a blank line here
to empty, in other words, the -viewDidUnload snippet will be removed. But note, there's a blank line after the implement. If you don't want to include it, use
:args **/*.m | argdo %s/^-\ (void)viewDidUnload\_.\{-}}//ge | update
instead.
Note: This will include lib files as well when you're in your project's root dir. I suggest go to your Controllers' root dir, then all files & you will be happy with the result. ;)
Tip:
After that, you'd better check whether all -viewDidUnload were removed, run the command below on terminal of your desired root dir:
$ find . -type f -iname "*.m" -exec grep -i "viewDidUnload" {} +
It should result with no output. Otherwise, some targets missed, you can locate it easily cause it'll list all files that not managed correctly, then just remove it manually (This might happen if your - (void)viewDidLoad is -(void)viewDidLoad without a space, or something else).
Finally, you can run
$ git diff -b --color-words
to see the result. Enjoy it! ;)
Further reading about the command
args **/*.m: Sets arglist to contain all .m files in current directory and it's subdirectories;
argdo: Run the following command(s) on all arguments in arglist;
%s/^-\ (void)viewDidUnload\_.\{-}}\n^$\n//ge: Vim RegEx to replace -viewDidUnload implement snippet to empty;
\_.: Find any character including end-of-line (linebreak).
\{-}: Match as few as possible (stopping at the first }, e.g. \{-}h will stop at the first h);
}: The last item to match;
\n: Line-break;
^$\n: blank line.
update: Save modification only if the buffer has been modified.
Reference
Search Across Multiple Lines
Search and Replace in Multiple Buffers
I'm new to internationalization and localization for iOS. I'm running genstrings:
find . -name \*.m | xargs genstrings -o en.lproj to generate my Localizable.strings files. It builds the file in alphabetical order (by key).
For ease of translation I'd prefer that the keys and values be ordered by their order of appearance in the .m files. Is this possible with genstrings? I couldn't find the relevant info on its man page.
You could do something like:
find . -name '*.m' -print | xargs -n1 genstrings -a
I'm sure there are more elegant ways. Perhaps just use ls *.m instead of the find. The strings are kept together by file with -a switch but they are still sorted within each file.
It is not possible to change the behavior of genstrings other than what it is allowed within the parameters specified in the manual:
https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/genstrings.1.html
but if you want to ease the translation you can use Linguan
http://www.cocoanetics.com/apps/linguan/
If you want to stick to genstrings and are having some trouble with it you can try this page, it offers a good explanation:
http://spritebandits.wordpress.com/2012/01/25/ios-iphone-app-localization-genstrings-tips/
But yeah returning to the main question, it is not possible in my knowledge.
I'm sure I'm misunderstanding something about ack's file/directory ignore defaults, but perhaps somebody could shed some light on this for me:
mbuck$ grep logout -R app/views/
Binary file app/views/shared/._header.html.erb.bak.swp matches
Binary file app/views/shared/._header.html.erb.swp matches
app/views/shared/_header.html.erb.bak: <%= link_to logout_text, logout_path, { :title => logout_text, :class => 'login-menuitem' } %>
mbuck$ ack logout app/views/
mbuck$
Whereas...
mbuck$ ack -u logout app/views/
Binary file app/views/shared/._header.html.erb.bak.swp matches
Binary file app/views/shared/._header.html.erb.swp matches
app/views/shared/_header.html.erb.bak
98:<%= link_to logout_text, logout_path, { :title => logout_text, :class => 'login-menuitem' } %>
Simply calling ack without options can't find the result within a .bak file, but calling with the --unrestricted option can find the result. As far as I can tell, though, ack does not ignore .bak files by default.
UPDATE
Thanks to the helpful comments below, here are the new contents of my ~/.ackrc:
--type-add=ruby=.haml,.rake
--type-add=css=.less
ack is peculiar in that it doesn't have a blacklist of file types to ignore, but rather a whitelist of file types that it will search in.
To quote from the man page:
With no file selections, ack-grep only searches files of types that it recognizes. If you have a file called foo.wango, and ack-grep doesn't know what a .wango file is, ack-grep won't search it.
(Note that I'm using Ubuntu where the binary is called ack-grep due to a naming conflict)
ack --help-types will show a list of types your ack installation supports.
If you are ever confused about what files ack will be searching, simply add the -f option. It will list all the files that it finds to be searchable.
ack --man states:
If you want ack to search every file,
even ones that it always ignores like
coredumps and backup files, use the
"−u" switch.
and
Why does ack ignore unknown files by
default? ack is designed by a
programmer, for programmers, for
searching large trees of code. Most
codebases have a lot files in them
which aren’t source files (like
compiled object files, source control
metadata, etc), and grep wastes a lot
of time searching through all of those
as well and returning matches from
those files.
That’s why ack’s behavior of not
searching things it doesn’t recognize
is one of its greatest strengths: the
speed you get from only searching the
things that you want to be looking at.
EDIT: Also if you look at the source code, bak files are ignored.
Instead of wrestling with ack, you could just use plain old grep, from 1973. Because it uses explicitly blacklisted files, instead of whitelisted filetypes, it never omits correct results, ever. Given a couple of lines of config (which I created in my home directory 'dotfiles' repo back in the 1990s), grep actually matches or surpasses many of ack's claimed advantages - in particular, speed: When searching the same set of files, grep is faster than ack.
The grep config that makes me happy looks like this, in my .bashrc:
# Custom 'grep' behaviour
# Search recursively
# Ignore binary files
# Output in pretty colors
# Exclude a bunch of files and directories by name
# (this both prevents false positives, and speeds it up)
function grp {
grep -rI --color --exclude-dir=node_modules --exclude-dir=\.bzr --exclude-dir=\.git --exclude-dir=\.hg --exclude-dir=\.svn --exclude-dir=build --exclude-dir=dist --exclude-dir=.tox --exclude=tags "$#"
}
function grpy {
grp --include=*.py "$#"
}
The exact list of files and directories to ignore will probably differ for you: I'm mostly a Python dev and these settings work for me.
It's also easy to add sub-customisations, as I show for my 'grpy', that I use to grep Python source.
Defining bash functions like this is preferable to setting GREP_OPTIONS, which will cause ALL executions of grep from your login shell to behave differently, including those invoked by programs you have run. Those programs will probably barf on the unexpectedly different behaviour of grep.
My new functions, 'grp' and 'grpy', deliberately don't shadow 'grep', so that I can still use the original behaviour any time I need that.