You are not logged in.

#101 2010-11-08 15:54:56

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Version 36: http://sprunge.us/REQA
Quick Install: wget -O- 'http://sprunge.us/REQA' > kingbash; chmod +x kingbash

This fixes those two problems.

Offline

#102 2010-11-09 13:26:22

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Kingbash - menu driven auto-completion

cool. tab completion seems to work nicely.
another thing I noticed is that if the line is longer then the width of the terminal, a shell would wrap the line, kingbash doesn't.  with kingbash the excess string is just not visible.


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#103 2010-11-10 20:03:14

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Version 37: http://sprunge.us/EBMG
Quick Install: wget -O- 'http://sprunge.us/EBMG' > kingbash; chmod +x kingbash

That's indeed a good idea. I added that as the default.

I fixed a bug in the help text about the calling function that uses the cursor save/restore escape codes. This part:

  if [[ $KBMOVE == B ]]; then
    echo -ne "\e[$KBLINES"A
  fi

Should become

  if [[ $KBLINES != 0 && $KBMOVE == B ]]; then
    echo -ne "\e[$KBLINES"A
  fi

I added the option --wraplonglines. The prompt will now always wrap unlike before, but this option will make all the items wrap. On the next line I thought it might look nice to have them right-justified. I think I got all the off-by-one errors that cause the window to scroll up or down because too many or not enough lines are deleted. It tries to respect the total amount of lines available (1/3 of the screen by default) but that means some items aren't visible that normally are. For walking down a list this should work fine. Scrolling up sometimes gives invisible items.

There is also a bug in the prompt having a long line in combination with --forceheight MAX.

Both bugs need a rewrite of the display code. I'll look into it later.

Offline

#104 2010-11-21 15:09:51

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Kingbash - menu driven auto-completion

@Procyon how about a code cleanup?  I was looking if it was possible to separate the "dmenu"-code into a separate python program, but the code (esp the main function) looks so convoluted, it scares me wink


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#105 2010-11-23 18:21:14

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Version 38: http://sprunge.us/PFfL
Quick Install: wget -O- 'http://sprunge.us/PFfL' > kingbash; chmod +x kingbash

I didn't find an easy way to fix the wrapline option. It should at least now always have the selected file in sight, except when lines are several pages long.

The example calling function now starts with this code to clear the input buffer. I used to use read without -n 1, but this doesn't work at all because without an enter in the buffer read won't accept it.

for ((unused=0; unused<20; unused++)); do read -n 1 -t 0.0000001; done

I added -bashcompletionexception
This is for completions that you don't want to run.
By default it is set to mplayer, because mplayer's bash completion adds all the files in the current directory.
If you want to add more be sure to add mplayer too. The format is
kingbash --bashcompletionexception 'mplayer git etc'

One very important Python 3 switch bug is fixed. READLINE_POINT wasn't working because bash expects characters to count as 3 per UTF8 character whereas the way Python counts unicode now is as only 1 per unicode character.

$ in filenames will now get escaped properly.

@Dieter@be:
Yeah it's becoming an issue. As I have to add more stuff like replacing sys.argv calls throughout the code with the optparse module it becomes a little better. But I really only care about the end result. Actually the biggest problem is that, if you remember I mentioned code cleanups in the past, that I looked into trying to find better/simpler ways to rewrite the code or fix the same problems, but I seriously end up just staring at the screen for an hour. Anyway, it shouldn't be too hard to isolate the dmenu code. It should all be separated with if/else (but that won't get you much of a speedup).

On that topic there is also no way I can split kingbash in a menu'ing and data gathering application because it really limits what features you can put in keys.

And I noticed you made a topic about bash completion. I couldn't reply without confusing others or assuming you use Kingbash for tab completion, but if someone is using --bashcompletion in Kingbash, it can access and use the files in /etc/bash_completion.d/ without any prior bash completion software running. I removed my /etc/bash.bashrc to start up faster.

Offline

#106 2010-11-23 21:30:05

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Kingbash - menu driven auto-completion

Procyon wrote:

On that topic there is also no way I can split kingbash in a menu'ing and data gathering application because it really limits what features you can put in keys.

That's too bad.  If the dmenu code would be in a separate program, i could package it, depend on it in my scripts, and feel more confident exploring the code.

Procyon wrote:

And I noticed you made a topic about bash completion. I couldn't reply without confusing others or assuming you use Kingbash for tab completion, but if someone is using --bashcompletion in Kingbash, it can access and use the files in /etc/bash_completion.d/ without any prior bash completion software running. I removed my /etc/bash.bashrc to start up faster.

how exactly do I use this?
I run `kingbash --bashcompletion` which shows me the usage, and when adding the --bashcompletion flag to kingbash in my kingbash.hs function, tab completion doesn't work (i.e. I type 'cat<tab>' and it completes to 'locate foo' which happens to be the first matching history entry)

Last edited by Dieter@be (2010-11-23 21:30:16)


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#107 2010-11-23 23:54:17

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

It needs a new function that doesn't use the -r argument.

Offline

#108 2011-01-20 09:48:08

aliel
Member
Registered: 2011-01-20
Posts: 1

Re: Kingbash - menu driven auto-completion

Hi i am a new member,

how can i sort list of suggestion by last accessed time,

example for "cd nano cp ...." command

and sorted by alpha for "ls ...."

I'm not a Python developer.

Thank's

Offline

#109 2011-01-21 02:22:12

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Welcome to the forums, aliel.

Version 39: http://sprunge.us/ORNc
Quick Install: wget -O- http://sprunge.us/ORNc > kingbash; chmod +x kingbash
Colorful diff: dwdiff -c <(curl -s http://sprunge.us/PFfL) <(http://sprunge.us/ORNc) | grep -C 2 $'\e\['

--prompt "STRING": to replace "Kingbash"
--atime / --mtime: sort by access / modification time. Also shows atime/mtime in square brackets (YYYY-MM-DD HH:mm).
--reverse: reverse the sort

I made the time sort stronger than directory sort, and weaker than recommendation sort.

Note that --reverse will put the latest item on top.

I also fixed a bug with the "append all items to prompt" bound to * or +, where unicode characters were not counted as 3 bytes long. I had previously fixed this for Insert and Enter.

Offline

#110 2011-01-21 15:00:46

George_K
Member
From: Russie, Saint-Pétersbourg
Registered: 2006-09-27
Posts: 75

Re: Kingbash - menu driven auto-completion

Hello, Procyon.
I have just found your tool and I appreciate it already!

By the way, the `Alternative with neater long line handling' part of interactive help is a bit damaged somehow: `echo' lines got mangled.

I've got a question too (this is how I found this thread), somebody might know: how to activate zsh-like path completion in bash (`/u/b<TAB>' → `/usr/bin/')?

Offline

#111 2011-01-21 19:01:46

George_K
Member
From: Russie, Saint-Pétersbourg
Registered: 2006-09-27
Posts: 75

Re: Kingbash - menu driven auto-completion

Procyon, there is another small problem.  Your script assumes that `/etc/bash_completion' exists (line 368: `source /etc/bash_completion'), which is not always the case.

Offline

#112 2011-01-22 03:55:33

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Version 40: http://sprunge.us/HPfc
Quick Install: wget -O- http://sprunge.us/HPfc > kingbash; chmod +x kingbash
Colorful diff: dwdiff -c <(curl -s http://sprunge.us/ORNc) <(curl -s http://sprunge.us/HPfc) | grep -C 2 $'\e\['

Thanks, George_K.

The alternative calling function is indeed broken. It happens with long lines when you are at the end of the screen. The one line (or more) scroll messes up the cursor save and load which use absolute positions. It also doesn't work with some multiplexers like tmux.

I can't think of a good way to fix it. The visual glitches in the original calling function shouldn't be that bad anyway.

I added --shortpath, which will turn one-letter paths e.g. /u/b into /u*/b. * is then expanded from bash. This is a bit of a hack, but coding this behavior in python isn't very pleasant.

* in paths is now always expanded this way. --shortpath only has influence on one-letter paths. When * is expanded then the file is not stat'd. This will give it a [SPC] tag without color. <-- EDIT I'll look into fixing this and some other rough edges

Only --bashcompletion will look for /etc/bash_completion. It will crash if it doesn't exist. Version 40 ignores the --bashcompletion code if /etc/bash_completion doesn't exist.

Version 40 also fixes some bugs with command line arguments after special keys (order not getting preserved etc) and a bug with the new time sort with CDPATH.

Last edited by Procyon (2011-01-22 07:54:09)

Offline

#113 2011-01-26 08:06:35

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

I haven't done a good bug search yet, but in the mean time try this:
http://sprunge.us/UKEC
wget -O kingbash http://sprunge.us/UKEC; chmod +x kingbash

It should fix:
- don't add * if the directory exists (with that I will make --shortpath the default)
- use path not filename (seems to be a lot less of a headache than I thought)
- this also makes it return the full path instead of *
- and it makes files stat'able, which is why I wanted to post it instead of delay further

Things to check/fix:
- case insensitivity (I think it can be fixed with something like /[uU]*/, but this won't work in cases where you use * in a longer tab-completion), I'll probably switch to find.
- special characters (seems to run through the built-in shell fixing function OK, I thought there would be a lot of issues with this too). If anything shows up as SPC (unstat'able) or returns wrong let me know.
- an older bug where unicode in the prompt causes the pointer to be off at the start.

Offline

#114 2011-02-05 15:09:13

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Version 41: http://sprunge.us/VSFH
Quick install: wget -O kingbash http://sprunge.us/VSFH; chmod +x kingbash
Diff: dwdiff -c <(curl -s http://sprunge.us/HPfc) <(curl -s http://sprunge.us/VSFH) | grep -C 2 $'\e\['

New Key: F3 will sort the list cycling through alphabetic & no-reverse -> atime & reverse -> mtime & reverse. The prompt will be changed to reflect the current sorting order.
Now it uses shopt -s nocaseglob in the * expansion bash code.
READLINE_POINT being off is fixed.

Offline

#115 2013-01-21 17:52:53

zeltak
Member
From: New England
Registered: 2010-08-07
Posts: 168

Re: Kingbash - menu driven auto-completion

Hya

all the links seem dead, is the app still avilable to try?

Z.

Offline

#116 2013-01-22 07:51:11

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,423

Re: Kingbash - menu driven auto-completion

the ncurses one is in aur, not sure if it is up to date.
the gambas one is in the first post


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#117 2013-01-22 14:33:37

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

Ah, you're right. Yeah, sprunge deletes links.

Here it is:
http://pastebin.com/wBWR5g1S

I have slightly hacked version. I think the main difference is that it prepends * when there are no matches.
Including something like:
mplayer tantei<TAB> turning into:
mplayer [KiteSeekers] Tentei Opera Milky Holmes.mkv
(or rather a menu for all Tantei episodes)
(as if mplayer *tantei<TAB> was typed)

A few days ago I actually started working on a minimal rewrite in bash, because the python script is huge and I don't understand it at all anymore. I hope it will be faster too.

I'm now at the point where I'm rewriting the menu code.

Offline

#118 2013-01-22 15:11:05

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,423

Re: Kingbash - menu driven auto-completion

Thanks Procyon, can't wait to test it!


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#119 2013-01-23 22:42:59

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

It's nearing completion. Here's a test version, and it was a success, it's much much faster:
http://pastebin.com/m1KCzjdk
It just needs to be sourced and it will bind to <TAB>.

I'm now going to use it for my day-to-day needs. Looking for bugs and things I forgot. If you find something missing let me know!
Priority of media files per command is already in.

Sorting by time is out. It's just not feasible with the way the file list is acquired (just a glob).
CTRL+C doesn't work on the menu for some reason. Only Escape. This should be solved by making a separate script file instead of a function. I'll try that next time.
Other Todo's are bringing directories to the top and completing commands after sudo and setsid etc. and completing files after =. Maybe add keys for left and right to go into other directories.

Offline

#120 2013-01-24 13:17:03

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,423

Re: Kingbash - menu driven auto-completion

I needed to dos2unix it (probably a pastebin or firefox issue), it works good but your older work provided the filesize, a scrollbar and more results.
Navigation by left-right (which is on yout ToDo) would be great!

-edit
sorry, i just seen the current page indicator smile

Last edited by kokoko3k (2013-01-24 13:19:07)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#121 2013-01-24 22:18:17

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

http://pastebin.com/aNWpV4mV

curl 'http://pastebin.com/raw.php?i=aNWpV4mV' | sed 's/\r$//' > kingbash.script
chmod +x kingbash.script
bind -x '"\t": out=$(kingbash.script "$PS1"); READLINE_LINE=$(echo "$out" | head -n -1); READLINE_POINT=$(echo "$out" | tail -n 1)'

This time I put it in a script. That way CTRL+C works, but the bind -x line becomes a bit more complex and all output has to go to STDERR.

There's a huge speedup this time. I took out the code that stat's every file. Only when a file is displayed in the menu is the size calculated and checked whether it's a directory.
For cd it will still stat every file though, to put all the directories first.
That means in an uncached directory of 2000 files, it will start displaying in 200 milliseconds instead of 7 seconds.

I added F2: change the command without exiting (selected file is preserved).
and F3: sort by time (it's a bit limited, but enough in my opnion).

Left and Right work, but when there's only one item, it's auto selected. Also on Left the directory you came from isn't selected. I think I may be able to fix both, but I haven't thought about how to yet.
I made it so you have to press Right twice. The first time it will show some information about the file or directory. This can easily be removed if you don't like it.

I played around a bit with the menu colors. Directories will now be underlined and matching media files will be bright blue.

The globbing got stuck on [abcd] patterns but that should be fixed now.

Offline

#122 2013-01-28 19:24:37

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

I decided to go back to a function anyway. It's just a bit simpler.
Other updates:
The page numbers will now be reverse colored if it's the last page.
The first Right on a file will `ls -l info` instead of `file` because `file` was slow.
Trying out escaping instead of single quotes.
You can now complete variable=filename
Some bug fixes.
Left will now select the originating directory.
Command completion after sudo etc.
And dotfiles can now be expanded when it's under a glob. E.g. vim ~/bashrc<TAB> will complete to vim ~/.bashrc

curl 'http://pastebin.com/raw.php?i=E9vsKfg6' | sed 's/\r$//' > kingbash.function

Any objections if I put the bash version on AUR instead of python?

EDIT: had a variable in the wrong spot. New one: http://pastebin.com/raw.php?i=E9vsKfg6

Last edited by Procyon (2013-01-28 21:36:15)

Offline

#123 2013-01-28 20:32:22

theGunslinger
Member
Registered: 2011-05-20
Posts: 300

Re: Kingbash - menu driven auto-completion

I'd actually prefer the bash version in the AUR. Thanks for your work, I'm having fun with it daily.

Offline

#124 2013-01-29 07:16:32

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,423

Re: Kingbash - menu driven auto-completion

I find the underline feature distracting and the need to press the right key twice useless for my needs.
Could you tell me how to disable them or maybe make that optional?
thanks!

-found it and disabled both
Here's what it looks like now:
taDl0Mg
what i'm still missing is the ability to display directories first and the item itself not being highlighted, but only the very first column.

Last edited by kokoko3k (2013-01-29 12:46:23)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#125 2013-01-29 14:32:49

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Kingbash - menu driven auto-completion

@kokoko3k: Yeah, of course, it was just an experiment.
Updates:
I put the info text for the selected file on F1. Right goes on at once.
I replaced directory underline with making the "size" field stand out more using unicode blocks: ▓▓▓▓
I got CTRL+C working by using a subshell for just `read`.
There was a bug with LC_ALL that messed with the prompt on really long lines. Now it uses LC_CTYPE. You should use a fresh shell to see the change.

I also forgot that the python script is a console dmenu. A function can't be called in an external script like that, so it has to be a separate file. I made a new small console dmenu in bash. You can move left and right in the prompt. F2 accepts the line as-is. Tab will fill in the current item. Spaces make an "AND"-like grep for each word.

curl 'http://pastebin.com/raw.php?i=RyGjKyaW' | sed 's/\r$//' > kingbash.function
curl 'http://pastebin.com/raw.php?i=JFc1ysn5' | sed 's/\r$//' > kbdmenu
chmod +x kbdmenu

Offline

Board footer

Powered by FluxBB