How to make terminal autocomplete when there are several files/directory?
Solution 1
Something that is a life-saver for me is to have bash cycle through the possibilities instead of showing a dumb list.
As bash is using readline
for its auto-completion, add the following lines to ~/.inputrc
Once you're satisfied and have thoroughly tested below solution for a few days/weeks, cut and paste (don't copy!) the same settings from ~/.inputrc
to /etc/inputrc
which contains the system-wide settings, making this available to all users on your system (including guest).
The codez:
# mappings to have up and down arrow searching through history:
"\e[A": history-search-backward
"\e[B": history-search-forward
# mappings to have left and right arrow go left and right:
"\e[C": forward-char
"\e[D": backward-char
# mapping to have [Tab] and [Shift]+[Tab] to cycle through all the possible completions:
"\t": menu-complete
"\e[Z": menu-complete-backward
then exit
your terminal (or remote terminal like putty) and open it again...
Examples:
When you have 3 files:
file1
,file2
andfile3
and you type:e fTabTabTab
it'll cycle through:
e file1 e file2 e file3
and when you want to cycle backwards, just hit Shift+Tab
When you type:
very-complicated-command with lots of command line parameters
and next time you need the same command, you just type:
very↑
and it'll type for you:
very-complicated-command with lots of command line parameters
This will save you a ton of time in bash! ;-)
Solution 2
After the 1st tab you need to insert more letters. So if you type
cd a
and hit tab you get nothing and after a second tab (immediately following) you get a list of the names starting with a
and then need to insert an f
to have it auto complete the remainder so
cd a
tabtabf
tabtab
will result in
cd afoo
Related videos on Youtube
OverMars
Updated on September 18, 2022Comments
-
OverMars almost 2 years
Update: Im trying to update an EF entity without knowing the column until run time. So I would like my front end to post to my api with a column name and its value, then have my api update the database by:
- Finding the column to be updated (using provided string)
- Update db using provided value
So given the following data inside my webapi controller:
string colName = 'firstName'; string colValue = 'Sam';
In my EF data retrieval, instead of
var user = db.Users.Where(x => x.firstName == colValue); //firstName is actual column name
can I do something like
var user = db.Users.Where(x => x.'colName' == x.colValue); //colName is the string representation of column
and the somehow update this give column, so something like:
user.colName = colValue; //where colName = 'firstName'
instead of
user.firstName = colValue;
I have researched Reflection quite a bit but I'm not sure where to begin or if such a task is even possible.
I could use a loop to retrieve like data like so:
foreach(var x in User.GetType().GetProperties()) { if(x.ToString() == colName) { var y = db.User.Where(z => z.firstName == colValue) }}
Any pointers, recommendations or suggestions would be greatly appreciated! Is this impossible?
-
Oren Hizkiya over 9 yearsWhat it your greater goal and why did settle on this approach? In general entity framework is meant to abstract away the details of the database so you can work with objects. This includes column names.
-
OverMars over 9 yearsI'd like to update database columns one at a time, as they change on the front end. It would be nice if the front end could tell the api/EF the column to update with a given value. So I would have a controller: UpdateColumn(string colName, string colValue)... and it would decide what column needs to be updated based on the string name of the column passed in from the front end.
-
muru about 9 years+1, interesting, but: 1.
~/.inputrc
might be preferable over/etc/inputrc
, and 2. I think you can set this inbash
directly: unix.stackexchange.com/q/55203/70524, unix.stackexchange.com/a/16926/70524 -
Erik over 7 yearsThis is quite nice, thanks (and have my upvote). Is there a universal way to show the options it'll loop through, which combines the best of both worlds? I like the tab+tab possibility with folders and subcommands, etc. so I don't have to remember them all (e.g.
git branch <tab through branches>
. However, if I could see a list and tab through its items, that would be great! For directories and filesls
is an option to see what items are available. However, for subcommands it is not that easy or obvious, unfortunately. -
np8 over 6 yearsThis works also on PuTTy! Just had to restart it once :)
-
Tobias about 6 yearsIMHO: This is the right way. I personally find the windows behavior very annoying. Consider the case where you have a lot of files starting with
a
and you need the last one. When you accidentally press tab aftera
you have to cycle through the list of all possible completions to get to the right one. -
Fabby almost 6 years@Erik: Apparently, what you asked for is possible but not going to edit my answer to keep things simple here. (deleted old comment that it is not possible)
-
Fabby almost 6 years@Tobias: when you accidentally hit [Tab] too early using the other system, there is still [Ctrl][K]... ;-)
-
sh.3.ll about 4 yearsHow to put this TAB markdown? @Fabby
-
Fabby about 4 years