How can I specify that fzf --preview should only find files within the current directory? - fzf

fzf --preview 'cat {}' gives me a two-pane terminal window of (left) a fzf fuzzy search for files and (right) a preview of said files.
When called, it starts out showing me /Users/tomnorway/Downloads, regardless of my current directory. I'd like to write a command that only finds files/folders within my current directory (recursively). Having read through man fzf to the best of my ability, I find no way to specify that. Does anyone have any advice?

From you response in the comments, given that the output of echo $FZF_DEFAULT_COMMAND is:
fd . /Users/tomnorway
You should go into your ~/.bashrc and replace the line:
export FZF_DEFAULT_COMMAND='fd . /Users/tomnorway'
with:
export FZF_DEFAULT_COMMAND='fd --type f'
Bonus
I also have an answer for if you want fzf to search a dedicated shortlist of
directories (e.g. Docs, Downloads, Pics, Vids, Admin, MyDir... etc.) regardless
of where you are in the filesystem
(https://stackoverflow.com/a/67019648/14467607). I like this because it
effectively means I can find any file at any time (but without cluttering the
fzf list with thousands of random files from various installations in my home
directory).

Related

Use fzf to search for history commands run in current directory only

Is it possible to use fzf to search for history commands run in current directory only? If it is not possible using fzf, is there any functionally similar tool that allows this?

My bashrc file has a comma in it

My bashrc file is listed like this when viewed in the file explorer:
,bashrc
I believe the filename should be formatted like this:
.bashrc
Will the comma affect how the program runs?
Is it ok to replace the comma with a period?
From this answer:
.bashrc is a shell script that Bash runs whenever it is started
interactively.
The .bashrc file must start with a period, not a comma, as it's a "hidden" file.
From wikipedia regarding hidden files:
In computing, a hidden folder (sometimes hidden directory) or hidden
file is a folder or file which filesystem utilities do not display by
default when showing a directory listing. They are commonly used for
storing user preferences or preserving the state of a utility, and are
frequently created implicitly by using various utilities.
Before renaming the file (replacing the comma with a period) you should first read it's contents and make sure that there is nothing potentially harmful there.
Someone could have potentially changed the period to a comma to ensure that the file isn't run while making risky or temporary changes.

PhpStorm minify multiple JavaScript files in 1

I wanted to minify my JavaScript files using PhpStorm's file watcher but I can't get it working the way I would like it to.
I have installed uglify-js. In the file watcher I tried the following:
Arguments: $FileName$ -o $FileDir$.min.js --style compressed
Output paths to refresh: $FileDir$.min.js
The problem is that there is just 1 file being minified each time not all in one.
The other problem is that I would like to output a sourcemap but I don't know how to do this nor where to put it (arguments or output paths).
I hope someone could help me with these settings.
Few notes on File Watchers:
File watchers were designed primarily to perform some external actions on file on save.
File watcher gets called for each modified file.
If you want to process multiple files in one go (for example: merge 2+ files into 1) using File Watcher then you need to hard code all participating files (as opposed to using current file macro $FileName$ for that), unless, of course, uglify supports file masks (e.g. /path/to/folder/*.js).
If you modify 2 files from the target list then File Watcher will be called for each of them so even with hard coded file names it will be performed twice (same job done twice).
Considering the above I suggest using Grunt or Gulp task for that instead -- they're more suitable for such requirements.
P.S.
If you wish you could actually use such grunt/gulp task inside File Watcher (same as calling it in terminal/console manually) but because of point #3 above the better solution would be using Grunt's/Gulp's watch module/functionality if you need automatic execution of task.

Preventing bzr-update changes to user-specific .cfg file

I have a project, hosted on launchpad, which contains a fairly user-specific configuration file.
Once the project is initially checked out, obviously this .cfg file should also be downloaded. However, further updates (via "bzr update") would ideally not alter this .cfg file, as the user would have made their own edits to it. These edits would be overridden / merged should (with potential conflicts) I push an update using the code with my own .cfg file - I don't want this to happen!
What's the best practice to avoid this? I can't really "bzr ignore", as then any future users checking out via bzr would then not have the .cfg file.
I could, of course, replace my .cfg file with the "stock" one each time I do a commit, but this seems a bit clunky.
Or equivalently clunky, supply the .cfg file separately.
What I'm looking for is a "single-shot" download, but never update subsequently.
Any advice?
This is a tricky problem, because version control systems in general are not engineered to have the fine-grained commit strategies needed for this approach. If you were operating in a controlled environment, you could use plugins or hooks to exclude certain files from commits etc., but that doesn't seem to be an option here. I'll add that bzr ignore won't help you, either, because it only prevents files from being added; it doesn't prevent commits or checkout of those files.
What you can do is generate the config file during build/setup/installation if it doesn't already exist. Something like:
#!/bin/sh
if [ ! -e configuration.cfg ]; then
cp etc/configuration.cfg.in configuration.cfg
fi
Here, you'd check in etc/configuration.cfg.in normally and run the above script at build/setup/installation (this could also be automated by a post_change_branch_tip hook in a controlled environment). You'd put the original in a different directory so that there's less of a risk of it getting edited by accident.

Creating a search app like EasyFind

On OS X there is a popular app called EasyFind that searches for strings inside of a files content or you can just do a name search. More importantly, it searches in hidden files and inside of package contents.
So my research with using the Spotlight API leads me to believe that it is not possible to do this. Should I assume EasyFind is doing this all manually without using any Cocoa search API?
If that is true, does anyone know of some code to get me started, even just pseudo?
Basically I want to build an app that will find every single image on the drive no matter where it is or what permissions it has. This also includes icon files.
One other thing I can't seem to find an answer to is whether or not you can do a search like this on the command line in OS X.
Thanks!
In the command line you can use the find command line tool. That gives you access to all the files in the filesystem if you run it with root permissions (sudo). You can pipe its results to grep to find for strings inside the files. You can also use the strings command line tool to look for strings inside binary files.
This is not very complicated to implement within a Cocoa App. Just Google for how to iterate through all the hard drive contents. NSFileManager could be a good place to start digging.
Also check out FindAnyFile. It is a nice app that does similar to EasyFind but just on file properties (name, dates, etc.). It doesn't read file contents.