Just found your bt and dt bash functions - wanted to say it's a great
idea and simply executed. Well done.
One small suggestion is that if a user has set $HISTTIMEFORMAT, then dt
returns the line from the history file with the timecode, i.e.:
[tlarcombe@hathi ~]$ dt
15:50:28 source ~/.bash_profile
bash: 15:50:28: command not found
Bash tries to execute the command with the timecode - so fails.
I will probably adapt the function to sed -i and delete everything up to
the first space. Might have a chance to look at it later and I'll send
you an amendment if I get it working properly.
Anyway, again - Good Job.
Best regards
T.
Here is the solution for me:
In the function dt(), change:
local cmd=$(cat $data | fzf -d'\t' --with-nth 2 --preview='echo -e
"\033[1m"{1}"\033[0m""\n\n"{3}' | cut -f1)
to
local cmd=$(cat $data | cut -d' ' -f2- | fzf -d'\t' --with-nth 2
--preview='echo -e "\033[1m"{1}"\033[0m""\n\n"{3}' | cut -f1)
This cuts the first column before writing it to .config/btdt/data
This is only a work around for people who tiomestamp their history
entires - and will break btdt if they don't.
ATB
T.
On 6/21/22 15:57, Tony Larcombe wrote:
> Just found your bt and dt bash functions - wanted to say it's a great > idea and simply executed. Well done.>> One small suggestion is that if a user has set $HISTTIMEFORMAT, then > dt returns the line from the history file with the timecode, i.e.:>>> [tlarcombe@hathi ~]$ dt> 15:50:28 source ~/.bash_profile> bash: 15:50:28: command not found>>> Bash tries to execute the command with the timecode - so fails.>> I will probably adapt the function to sed -i and delete everything up > to the first space. Might have a chance to look at it later and I'll > send you an amendment if I get it working properly.>>> Anyway, again - Good Job.>> Best regards>>> T.>>
Hi Tony, thanks for your kind words and suggestions. I'm glad you found
the idea useful.
> In the function dt(), change:>> local cmd=$(cat $data | fzf -d'\t' --with-nth 2 --preview='echo -e > "\033[1m"{1}"\033[0m""\n\n"{3}' | cut -f1)> to> local cmd=$(cat $data | cut -d' ' -f2- | fzf -d'\t' --with-nth 2 > --preview='echo -e "\033[1m"{1}"\033[0m""\n\n"{3}' | cut -f1)>
I just realized the whole thing is horribly buggy: it's saving the
history timestamp in the data. That's obviously unintended! Thanks for
catching that. It seems `bt` was dumping needlessly the history
timestamp and I was blindly going around that in the `dt` part. Huh.
I guess the proper way to fix this is to make `bt` a bit more
intelligent in how it parses the history entries and saves them. I think
I will set up a public repository for btdt to make collaborating easier!
--
Antoine Kalmbach
Oh never mind, the timestamp is there so that fzf can present entries in
the correct order. `cut` is then used to get the actual command data.
So that would be an obvious improvement: make sure the data that enters
the data file is properly formated. Possibly with HISTTIMEFORMAT set
it's probably a good idea to use date/strptime to actually parse the
date out of it.
I could also make the preview part of btdt to not show the
timestamp... but it could be useful to have it there.
Anyway, I set up a repository here https://git.sr.ht/~ane/btdt
--
Antoine Kalmbach
Cool!
Thanks again - good project - nicely written solution.
Previously, I used bmenu to do tasks such as ssh or sshfs mount my
personal servers. It was very little effort to adapt the bmenu entries
to fit in the .config/btdt/data file. Now, rather than nested bmenus
(because the limit is 10 entries, and I need a 'back' option, I have
everything in one place in the dt() function. (oh, and I put the code in
.bash_function instead of profile = it just kind of keeps things neat
(along with .bash_alias) all called from .bashrc
I really like it when someone comes up with a solution to make their own
life easier and shares it with the community - this is the linux ethos.
You are the model! You are brilliant! :-)
Best regards
T.
On 6/22/22 10:01, Antoine Kalmbach wrote:
> Oh never mind, the timestamp is there so that fzf can present entries in> the correct order. `cut` is then used to get the actual command data.>> So that would be an obvious improvement: make sure the data that enters> the data file is properly formated. Possibly with HISTTIMEFORMAT set> it's probably a good idea to use date/strptime to actually parse the> date out of it.>> I could also make the preview part of btdt to not show the> timestamp... but it could be useful to have it there.>> Anyway, I set up a repository here https://git.sr.ht/~ane/btdt>
Tony Larcombe <tony@larcombe.tech> writes:
> Cool!>> Thanks again - good project - nicely written solution.>> Previously, I used bmenu to do tasks such as ssh or sshfs mount my > personal servers. It was very little effort to adapt the bmenu entries > to fit in the .config/btdt/data file. Now, rather than nested bmenus > (because the limit is 10 entries, and I need a 'back' option, I have > everything in one place in the dt() function. (oh, and I put the code in > .bash_function instead of profile = it just kind of keeps things neat > (along with .bash_alias) all called from .bashrc
Oh yeah, w.r.t. to submenus a cool feature to add to fzf would be
'narrowing'. So for instance if you have lots of commands that begin
with 'git', such as 'git status' and 'git pull', etc., it would be nice
if one could, after entering 'git', narrow the possible candidates to
the results already seen.
So you begin with
git|
git status
git pull
and then hit the narrowing key, you are left with
|
status
pull
(| represents the cursor here). This would make it easy to do "submenus"
so that results from other matches can be "excluded"
>> I really like it when someone comes up with a solution to make their own > life easier and shares it with the community - this is the linux ethos. > You are the model! You are brilliant! :-)
Thank you for your kind words.
--
Antoine Kalmbach