shellcheck vscode "shellcheck.ignorePatterns" for all files with no extension - visual-studio-code

I am using the shellcheck vscode extension and I would like shellcheck to ignore files everywhere that do not have a file extension. I have tried many different glob patterns and nothing works.
The closest I got was:
"shellcheck.ignorePatterns": {
"*[!(.)]/**": true
}
But it really wasn't close.
Does anyone know the magic sauce?

It seems that an extensionless file cannot be globbed.
I ended up not using the vscode shellcheck extension and used an inclusive approach with shellcheck on the command line, offloading the task of what to include to find.
All my scripts that needed to be linted were .sh files so this worked:
find . -type d \( -name node_modules -o -name vendor -o -path /tmp \) -prune -false -o -name '*.sh' -exec shellcheck {} \;
I would have liked to keep the bash linting in vscode but I had to settle for the above solution due to the limitation of globs/vscode.

Related

Rename files in sub-directories using find and rename

i wish to rename files with single digit numbers by adding a "0" in front, while ignoring files with double digit numbers, for example: 1.fileA, 2.fileB to 01.fileA, 02.fileB, and ignoring files 10.fileK, 11.fileL
when i use the following command, nothing happens. i assume it's because find returns the full path of the filename for which my rename function does not work. below, mediaDir is the path to my folder where my media files are located.
i tried the following but it still does not work:
find "$mediaDir" -type f -name "*.mp4" -exec rename 's/^(\d)\./0$1./' {} \;
so i tried the following instead, which also does not rename the files:
find "$mediaDir" -type f -name "*.mp4" -exec rename 's/^(\d)\./0$1./' $(basename {}) \;
although the following correctly lists out the basename of the files without the fullpath
find "$mediaDir" -type f -name "*.mp4" -exec basename {} \;
i have spent a whole day googling and trying but to no avail. please help.
After struggling further to understand the find command, thanks to Kusalananda who did a great job explaining "find" that "man find" does an incomplete job of:
Basic usage of -exec
In my question above, -exec doesn't work because find returns the full path to the found file, which makes my rename's regex using ^ fail since the digit to be appended to is no more at the start of the string, being within the full path.
Using "-execdir" instead, returns only the filename minus the path; however, GNU find prefixes the returned filename with "./" which defeats my regex. the following finally worked:
find "$mediaDir" -type f -name "*.mp4" -execdir rename 's/\/(\d)\./\/0$1./' {} \;
Note that the "^" is no more in my regex expression, due to the "./" prefix that "find" appends
To use -exec instead of -execdir, the following worked:
find "$mediaDir" -type f -name "*.mp4" -exec basename {} \; -exec rename 's/\/(\d)\./\/0$1./' {} \;
It seems that "-execdir" is shorter and better than "-exec".
Use find with regex to match only one digit and then process the output in a loop, executing mv to rename the file.
while read file;
do
filename=${fil3##*/}; # Extract the directory
dir=${file%/*} # Extrasct the file name
mv "$file" "$dir/0$filename" # Execute the move command
done <<< "$(find /path/to/dir -regextype posix-extended -regex "^.*/[[:digit:]]{1}\.file.*")"

Universal ctags with emacs

Sorry I am trying to configure ctags with emacs but I am in trouble.
I compiled global with this configure:
./configure --with-universal-ctags=/usr/local/bin/ctags
and I executed make && make install.
Then I changed the default target in the file .globalrc from native to new-ctags.
Finally I executed ggtags-create-tags within emacs.
Unfortunately I got the error
‘gtags’ non-zero exit: gtags: execvp failed.
gtags: unexpected EOF.
Can anyone help me, thanks
Using universal ctags is as simple as:
Run over a project (-R is to walk the project recursively, and -e is to use Emacs-compatible syntax):
$ ctags -eR
Alternatively if you like to only include files with certain extensions, you can use -a (append, creates a file if doesn't exist) option with find utility, like:
$ find -name "*.cpp" -print -or -name "*.h" -print -or -name "*.hxx" -print -or -name "*.cxx" -print | xargs ctags -ea
Run M-x visit-tags-table in Emacs, and navigate to the created TAGS file.

alternative to 'rename' command in CentOS 5.9

I need to rename all files whose name contains the substring 200at and substitute it with 200_at.
In Ubuntu, I would do:
find . -type f -name '*200at*' -exec rename -n 's/200at/200_at/' {} \;
In CentOS (version 5.9) it doesn't work. The command rename doesn't seem to support perl expressions and the above command does nothing at all.
Any ideas for an alternative?
In my experience with CentOS, we always used the mv (move) command for renaming things. ie:
mv 200at ./200_at
hope that works as your alternative.

how to set folder path for gtags

I am new to gtags, and have a question. I have a big project, such as android AOSP, I want gtags to parse some folders, how can I achieve it with gtags? I searched and got solution:
use -f option with gtags, it seems doesn't support folders
Is there any good idea that I can set the folders path and gtags only process those folders?
UPDATE: author of the question came up with a better solution in the comments. I'm adding it here so it's easier to find:
.. create tag file in the sub-directories I need, and add the directories
to GTAGSLIBPATH when loading the project,
My answer:
You can limit what gtags indexes by adding list of files/directories to skip keyword in ~/.globalrc or /etc/gtags.conf. Here's a sample gtags.conf file.
The problem is that often global/gtags packages don't install gtags.conf (at least it's not there in global-5.7.1-2 on ubuntu 12.04), so you'll need to either get it from global source distribution, or use someone else's gtags.conf as a reference. For instance here.
Something like this should work. Note that leading / means from the top of the tree. Without it gtags will skip matching entries anywhere in the tree.:
common:\
:skip=/skip-this-dir/,/lib/and-this/,/include/and-this-one-too/:
The -f option is premised on find(1). Please try the followings.
$ find folder1 folder2 folder3 -type f -print | gtags -f -
or
$ find folder1 folder2 folder3 -type f -print >gtags.files
$ gtags
This is my bash function to get rid of files and paths including 'dummy' and 'win':
function gtagsupdate {
find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" | grep -v dummy | grep -v win | gtags -f -
}

Deleting empty (zero-byte) files

What's the easiest/best way to find and remove empty (zero-byte) files using only tools native to Mac OS X?
Easy enough:
find . -type f -size 0 -exec rm -f '{}' +
To ignore any file having xattr content (assuming the MacOS find implementation):
find . -type f -size 0 '!' -xattr -exec rm -f '{}' +
That said, note that many xattrs are not particularly useful (for example, com.apple.quarantine exists on all downloaded files).
You can lower the potentially huge number of forks to run /bin/rm by:
find . -type f -size 0 -print0 | xargs -0 /bin/rm -f
The above command is very portable, running on most versions of Unix rather than just Linux boxes, and on versions of Unix going back for decades. For long file lists, several /bin/rm commands may be executed to keep the list from overrunning the command line length limit.
A similar effect can be achieved with less typing on more recent OSes, using a + in find to replace the most common use of xargs in a style still lends itself to other actions besides /bin/rm. In this case, find will handle splitting truly long file lists into separate /bin/rm commands. The {} is customarily quoted to keep the shell from doing anything to it; the quotes aren't always required but the intricacies of shell quoting are too involved to cover here, so when in doubt, include the apostrophes:
find . -type f -size 0 -exec /bin/rm -f '{}' +
In Linux, briefer approaches are usually available using -delete. Note that recent find's -delete primary is directly implemented with unlink(2) and doesn't spawn a zillion /bin/rm commands, or even the few that xargs and + do. Mac OS find also has the -delete and -empty primaries.
find . -type f -empty -delete
To stomp empty (and newly-emptied) files - directories as well - many modern Linux hosts can use this efficient approach:
find . -empty -delete
find /path/to/stuff -empty
If that's the list of files you're looking for then make the command:
find /path/to/stuff -empty -exec rm {} \;
Be careful! There won't be any way to undo this!
Use:
find . -type f -size 0b -exec rm {} ';'
with all the other possible variations to limit what gets deleted.
A very simple solution in case you want to do it inside ONE particular folder:
Go inside the folder, right click -> view -> as list.
Now you'll find all the files listed as a list. Click on "Size" which must be a column heading. This will sort all the files based on it's size.
Finally, you can find all the files that have zero bites at the last. Just select those and delete it!