I have a shell pattern that marks some files as "boring" namely backup files, pyo files, vim backups, autogenerated directories and the like. Let's call it $BORING_STUFF.
zstyle ':completion:*' file-patterns \
'%p:globbed-items' \
'*(^-/):regular-files' \
'*(^-/):boring-files' \
'.*(^-/):hidden-files' \
'*(-/):regular-directories' \
'*(-/):boring-directories' \
'.*(-/):hidden-directories'
In this case, I have the scope of each group also constrained by applicable ignore-patterns. (Such that boring-files contains only boring files and regular-files does not contain boring files)
I'd like bold items to always show up, and other items only show up if there are no other matches. (Aka. touch <tab> will show regular directories and regular files but not hidden files, while touch .<tab> will show hidden files.)
globbed items
directories
regular directories
boring directories
hidden directories
files
regular files
boring files
hidden files
Here we go.
setopt extended_glob
zstyle ':completion:*' file-patterns \
"^($BORING_FILES|.*)(-/):directories:normal\ directories %p~($BORING_FILES|.*)(^-/):globbed-files:normal\ files" \
"^($BORING_FILES|.*)(^-/):noglob-files:noglob\ files" \
".*~($BORING_FILES)(^-/):hidden-files:hidden\ files .*~($BORING_FILES)(-/):hidden-directories:hidden\ directories" \
"($BORING_FILES)(^-/):boring-files:boring\ files ($BORING_FILES)(-/):boring-directories:boring\ directories" \
zstyle ':completion:*' group-order \
builtins expansions aliases functions commands globbed-files \
directories hidden-files hidden-directories \
boring-files boring-directories keywords viewable
Related
I'm trying to check how many lines of code I contributed to the project I work, but only in relevant files such as .java and .story, not sure if there any other relevant types, and I want to ignore any other file types (I added some files for unit tests and don't want to consider them in this counting).
I also want to know if there is a better way to get this information.
I used this command:
git log --shortstat --author "<author>" --since "<beginDate>" --until "<endDate>" \
| grep "files\? changed" \
| awk '{files+=$1; inserted+=$4; deleted+=$6} END \
{print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
log can get glob patterns as the last argument.... so you could say
git log whatever conditions -- '*.java' '*.txt'
Which will only consider logging those files (just make sure that bash doesn't expand them.... that's why I used quotes).
Although I have experienced this with several GNU utilities already, let me give a specific example. I tried to install tar-1.30, which was downloaded from:
https://ftp.gnu.org/gnu/tar/tar-1.30.tar.xz
The official gnu ftp (via http). I build it from source after configuring without any issues. However the install-man make rule is missing even from the Makefile.in that comes with tar. Here are all of the documentation targets right from the Makefile.in file, with the newlines between them removed for brevity:
dvi: dvi-recursive
dvi-am:
html: html-recursive
html-am:
info: info-recursive
info-am:
install-data-am:
install-dvi: install-dvi-recursive
install-dvi-am:
install-exec-am:
install-html: install-html-recursive
install-html-am:
install-info: install-info-recursive
install-info-am:
install-man: <==
install-pdf: install-pdf-recursive
install-pdf-am:
install-ps: install-ps-recursive
install-ps-am:
Notice that the install-man target (to which I added a <== so it is easy to find) leads nowhere (i.e., has no further dependencies), thus causing no man pages to be created. The info pages, on the other hand, get created just fine, because the install-info leads to install-info-recursive and actual steps to build them down the line.
install-man is mentioned in the .PHONY line as indicated by the <==, below:
.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \
am--refresh check check-am clean clean-cscope clean-generic \
cscope cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \
dist-gzip dist-hook dist-lzip dist-shar dist-tarZ dist-xz \
dist-zip distcheck distclean distclean-generic distclean-hdr \
distclean-local distclean-tags distcleancheck distdir \
distuninstallcheck dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \ <==
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
installdirs-am maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \
tags-am uninstall uninstall-am
..., but it (i.e., install-man) is a do-nothing build step. Why is this and how do I get man pages installed when building tar and other GNU utilities that have an empty install-man target?
I downloaded and installed SyntaxNet following Syntax official documentation on Github. following the documentation (annotating corpus) I tried to read a .conll file named wj.conll by SyntaxNet and write the results in wj-tagged.conll but I could not. My questions are:
does SyntaxNet always reads .conll files? (not .txt files?). I got a bit confused as I knew SyntaxNet reads .conll file for training and testing process but I am a bit suspicious that it is necessary to convert a .txt file to .conll file in order to have their Part Of Speach and Dependancy Parsing.
How can I make SyntaxNet reads from files (I tired all possible ways explain in GitHub documentation about SyntaxNet and It didn't work for me)
Add these declaration lines to "context.pbtxt" at the end of the file. Here "inp" and "out" are the text files present in the root directory of syntexnet.
input {
name: 'inp_file'
record_format: 'english-text'
Part {
file_pattern: 'inp'
}
}
input {
name: 'out_file'
record_format: 'english-text'
Part {
file_pattern: 'out'
}
}
Add sentences to the "inp" file for which you want tagging to be done and specify them in shell the next time you run syntaxnet using --input and --output tags.
Just to help you a bit more I am pasting an example shell command.
bazel-bin/syntaxnet/parser_eval \
--input inp_file \
--output stdout-conll \
--model syntaxnet/models/parsey_mcparseface/tagger-params \
--task_context syntaxnet/models/parsey_mcparseface/context.pbtxt \
--hidden_layer_sizes 64 \
--arg_prefix brain_tagger \
--graph_builder structured \
--slim_model \
--batch_size 1024 | bazel-bin/syntaxnet/parser_eval \
--input stdout-conll \
--output out_file \
--hidden_layer_sizes 512,512 \
--arg_prefix brain_parser \
--graph_builder structured \
--task_context syntaxnet/models/parsey_mcparseface/context.pbtxt \
--model_path syntaxnet/models/parsey_mcparseface/parser-params \
--slim_model --batch_size 1024
In the above script the output(POS tagging) of the first shell command is used as an input for the second shell command, where the two shell commands are seperated by "|"
just a quick help if you want to save the output of demo in a .txt file:
try echo "open file X with application Y" | ./demo.sh > output.txt
it gives you sentence tree to the current directory.
In command line, How can we recursively find out all the zip files in a directory and its sub directories and keep only the latest modified 5 files and delete the remaining.
The files paths would be something like below:
basedirectory/2015/12/18/abc.zip
basedirectory/2015/12/18/def.zip
basedirectory/2015/12/18/ghi.zip
basedirectory/2015/12/18/jkl.zip
basedirectory/2015/12/08/mno.zip
basedirectory/2015/12/08/pqr.zip
basedirectory/2015/12/08/stu.zip
basedirectory/2015/12/07/stu.zip
I have a way, but it involves several (easy) steps. There are probably more elegant ways of doing this, but here is how I know how. They come from a couple sources, which I list at the end of my answer. You will use the already installed utilites cd, find, ls, rm and head. it will involve a creating and executing two bash scripts.
Open a terminal and change into your base directory with cd ~/basedirectory
This sets up the following commands. It is important that you stay in this directory for the rest of the commands.
Type findpwd-name *.zip > find_zip
This creates a list of all the zip files with the full path relative to the directory you changed in to. Instead of printing them to the screen, it writes them to a find_zip file in the directory you changed into.
type cp find_zip remove_old_zip
This creates a second, duplicate file that you will later use to delete the old files.
Open the find_zip file in your favorite text editor. If you're not used to using any, you can use gedit. If you don't have it, install it with sudo apt-get udpate && sudo apt-get install gedit
Do a search and replace as follows (in gedit): search for \n , and replace it with " \\n"
This places the list of folders within quotes. the first backslash places a "\" at the end of each line, which means continue reading the next line and execute all the code together. The \n preserves the line endings. The last " puts a quote at the beginning of each line. You need the quotes to escape special characters like ' and ( that may be in your file name.
Create 2 new lines at the top of the file and type:
!/bin/bash
ls -lt \
The first line turns your file into a bash script. The second line will list all the files you found with the find command and order them by date.
Create a new line at the bottom of your file and type: | head -5. Save and exit the file.
| is a "pipe" that will take the output of the ordered file list that ls creates and feed it into the head command. The head command will list just the 5 most recently modified files and display or print them on your screen.
As a result of steps 5-7, your file should go from looking like this:
basedirectory/2015/12/18/abc.zip
basedirectory/2015/12/18/def.zip
basedirectory/2015/12/18/ghi.zip
basedirectory/2015/12/18/jkl.zip
basedirectory/2015/12/08/mno.zip
basedirectory/2015/12/08/pqr.zip
basedirectory/2015/12/08/stu.zip
basedirectory/2015/12/07/stu.zip
to this:
#!/bin/bash
ls -lt \
basedirectory/2015/12/18/abc.zip \
basedirectory/2015/12/18/def.zip \
basedirectory/2015/12/18/ghi.zip \
basedirectory/2015/12/18/jkl.zip \
basedirectory/2015/12/08/mno.zip \
basedirectory/2015/12/08/pqr.zip \
basedirectory/2015/12/08/stu.zip \
basedirectory/2015/12/07/stu.zip \
| head -5
Type bash find_zip into in the terminal. With your newfound list of the 5 most recent files, open up the remove_old_zip file created in step 3.
You will also be turning this file into a bash script, but it will remove all but the five newest files.
Delete the lines in the remove_old_zip file containing the 5 files you want to keep.
Do a search and replace as follows (in gedit): search for \n , and replace it with " \\n"
This is the same as step 5.
Create 2 new lines at the top of the file and type:
!/bin/bash
rm \
This is similar to step 6 except that rm will delete the files still listed.
remove the final \ on the final line of the remove_old_zip file. Save and exit.
Type bash remove_old_zip.
Type rm find_zip remove_old_zip.
This remove the two scripts, which are now useless since the files have been deleted.
sources:
How can I list (ls) the 5 last modified files in a directory?
http://www.geekinterview.com/talk/758-how-to-continue-to-next-line.html
List files recursively in Linux CLI with path relative to the current directory
I have write the code according to book*learning vi and vim* p202
set statusline=%<%t%h%m%r\ \ %a\ %{strftime(\"%c\")}%=0x%B\
\\ line:%1,\ \ col:%c%V\ %P
i write the sentence in my _vimrc ,when i open a file ,an mistake occur .
Unknown option: %{strftime("%c")}%=0x%B\\
what is the matter?
Just before the %{strftime, you have two space characters, and only the first one is properly escaped with \. Therefore, Vim thinks the option value ends there and another option name begins. You need to either remove that additional space, or escape it (same for later occurrences of multiple spaces):
set statusline=%<%t%h%m%r\ \ %a\ \ %{strftime(\"%c\")}%=0x%B\
\\ \ line:%1,\ \ \ \ col:%c%V\ %P
As this is cumbersome and hard to read and edit, an alternative is to use :let, which avoids that escaping:
let &statusline = '%<%t%h%m%r %a %{strftime("%c")}%=0x%B line:%1, col:%c%V %P'