You are not logged in.

#126 2013-01-29 14:51:33

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

Re: Kingbash - menu driven auto-completion

kokoko3k wrote:

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.

Do you mean you want it to look like in your screenshot? I prefer having the entire row selected. Or do the colors make it hard to read?

Directories first is possible, but it will slow things down. I'll have to make that a command line option.

Offline

#127 2013-01-29 15:38:03

kokoko3k
Member
Registered: 2008-11-14
Posts: 1,445

Re: Kingbash - menu driven auto-completion

Wops, sorry, the line not totally highlighted was due to my changes.

Offline

#128 2013-01-29 16:50:19

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

Re: Kingbash - menu driven auto-completion

Small bugfix for the menu:
It needed redirect for tput `tput rmam > /dev/tty` or it won't work if stdout is redirected.
Backspace now reloads the list.

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

You can use a pop-up dmenu like this, really similar to what I've said before:

#! /bin/bash
rm /dev/shm/menu 2>/dev/null
cat > /dev/shm/inmenu
xterm -e bash -c 'answ=$(cat /dev/shm/inmenu | kbdmenu); echo -n "$answ" > /dev/shm/menu'
while sleep 0.1; do [ -f /dev/shm/menu ] && break; done
cat /dev/shm/menu
rm /dev/shm/menu
rm /dev/shm/inmenu

Offline

#129 2013-01-29 17:31:08

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

Re: Kingbash - menu driven auto-completion

Here it is with the option to group directories first. You have to comment the right bind line at the bottom.

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

EDIT: I botched one thing up. I wanted to add + to select all, but bound it to * instead. What + will do is add a * and then quit.
New link: http://pastebin.com/raw.php?i=Wys5sheX

EDIT2: kbdmenu also didn't work with /dev/tty redirect. It just had to redirect to stderr. And I changed outputting the input line if there are no matches and you press enter.

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

Last edited by Procyon (2013-01-30 11:28:14)

Offline

#130 2013-01-30 15:24:16

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

Re: Kingbash - menu driven auto-completion

Small update:

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

Kingbash will now put variables back when you use them. Like I have $b set to ~/bin, so when I do: vim $b/king<TAB> it will keep the $b. The menu will still show the real value though. Same goes for ~. It does give a bug where it replaces the first instance of the value is should replace to a variable, but I think it's really rare, example:
smallvar=m
vim m$smallvar.tx<TAB> => vim $smallvarm.txt
(the m in vim isn't expanded in the first place)

kbdmenu now has a <delete> bind.

I think I'll put it up on AUR like this.

Offline

#131 2013-02-01 12:55:15

kokoko3k
Member
Registered: 2008-11-14
Posts: 1,445

Re: Kingbash - menu driven auto-completion

With konsole and xterm it happens that the last history line gets erased after selecting something from the menu.

Gozer ~ # source /tmp/kingbash.function
Gozer ~ # cd /tmp

then i type ls [TAB]

Gozer ~ # source /tmp/kingbash.function 
Gozer ~ # cd /tmp
p0/5: ls   
▓▓▓▓|.ICE-unix
▓▓▓▓|.Test-unix
4,0K|.X0-lock
▓▓▓▓|.X11-unix
▓▓▓▓|.XIM-unix
▓▓▓▓|.font-unix
4,0K|.ktorrent_kde4_0.lock
▓▓▓▓|.wine-0
4,0K|7zG1.txt
748K|8517-Nanashi no Game translation E&D.rar
▓▓▓▓|CRX_75DAF8CB7768
8,0K|FakeInput.conf

...then i select the first result and hit the "right" key:

Gozer ~ # source /tmp/kingbash.function 
Gozer ~ # cd /tmp
p0/0: ls .ICE-unix/  
   0|.ICE-unix/15792

then i hit "return"

Gozer ~ # source /tmp/kingbash.function 
Gozer tmp # ls .ICE-unix/15792 

see that the line:

Gozer ~ # cd /tmp

is gone.

Offline

#132 2013-02-01 16:31:26

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

Re: Kingbash - menu driven auto-completion

I see. It's because xterm doesn't treat the 0 as 0 lines in "\e[0A" (move up X lines).

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

Offline

#133 2013-02-01 19:28:40

kokoko3k
Member
Registered: 2008-11-14
Posts: 1,445

Re: Kingbash - menu driven auto-completion

Trying now.
--edit
It works, thanks!

Last edited by kokoko3k (2013-02-01 19:30:32)

Offline

#134 2013-02-02 13:21:02

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

Re: Kingbash - menu driven auto-completion

Update: + and Insert will now add filenames to the prompt. Insert will stay in the program.

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

Does anyone have any feature requests?

Offline

#135 2013-02-05 12:21:09

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

Re: Kingbash - menu driven auto-completion

I'm probably doing something wrong but completion doesn't seem to work if I start typing a folder name in the current directory and hit tab.

An example with Down<TAB>

┌─[tingol][mephisto][~]
└──╼ ls
cmus-notify  Downloads  Dropbox  homepage.html  homepage.py  index.htm  Music  README.md  Skripte  Source  style.css
┌─[tingol][mephisto][~]
p0/-1: Down  

Offline

#136 2013-02-05 19:52:32

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

Re: Kingbash - menu driven auto-completion

@theGunslinger:
You're right, I forgot about that. It should work now. I also fixed a few invalid characters that may appear in an array subscript like `, @ and *.
Insert and Plus now add a space after directories.
kbdmenu has a small update in the prompt.

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

Offline

#137 2013-02-06 08:18:52

kokoko3k
Member
Registered: 2008-11-14
Posts: 1,445

Re: Kingbash - menu driven auto-completion

Oh, a feature request (or maybe is implemented by some hotkey).
could you add "../" as the first directory result (if current dir is not "/" of course)?

-Edit
Anopther thing ;
If i hit <TAB> as the first key, the cursor just moves right.
Is that expected instead of listing the current directory?

Last edited by kokoko3k (2013-02-06 08:51:50)

Offline

#138 2013-02-06 12:41:31

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

Re: Kingbash - menu driven auto-completion

Left goes up a directory. That should make a ../ entry unnecessary.

<TAB> when the line is empty gives a literal tab. Mainly for pasting commands from a script which tend to have tabs. This can be put on a timer, so you can press just tab and get some other behavior.
It used to list command names, but listing files in the current directory is possible too. Maybe something like after you selected a file it will put the cursor at the start of the line so you can enter a command.

Offline

#139 2013-02-06 13:34:07

kokoko3k
Member
Registered: 2008-11-14
Posts: 1,445

Re: Kingbash - menu driven auto-completion

Thanks, Left to go up is fine, i didn't know.
As for the need to paste scripts part into the terminal, the problem persists if i paste "<TAB> script text <TAB> script text" (kingbash completes), so maybe a timer would be necessary anyway?

Last edited by kokoko3k (2013-02-06 13:34:40)

Offline

#140 2013-02-06 19:04:54

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

Re: Kingbash - menu driven auto-completion

Yeah, I put it on a timer now. 0.1ms seemed to be enough, but I put it on 2ms just to be sure.
So if you press <tab> on an empty line now, you can complete a file, afterwards it will put the cursor at the start of the line.

I also made it so that command completions from scratch like with F2 and deleting all characters makes it so that it will prompt for the first key.
Because a list of all commands sometimes gives kind of an annoying delay.

I also added a help bar at the bottom. You can remove it by running the bind -x command with "nohelp" as an argument:

bind -x '"\t":kb_main nohelp'

It's in the examples at the bottom of the file too.

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

Offline

#141 2013-02-10 12:35:48

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

Re: Kingbash - menu driven auto-completion

There was a problem in the way strings are split. It will now exit when it's stuck on something. I think it's a bug in bash, but I can't repeat it outside this script.

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

Offline

#142 2013-02-11 15:50:15

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

Re: Kingbash - menu driven auto-completion

EDIT: It's fixed in the next version!

I wrote an example script that shows the bug clearly, please try it out:

#! /bin/bash

function bb() {
#	READFIRST="${READLINE_LINE::$READLINE_POINT}"
	READFIRST=$1
	IFS=$' \t\n'

	last="${READFIRST##* }"
	rest="${READFIRST% *}"
	before=

	while [[ -z "$before" ]] ; do
echo REST:$rest:
echo LAST:$last:
		if [[ "${rest: -1}" == '\' ]]; then
			last="${rest##* } $last"
			oldrest=$rest
			rest=${rest% *}
			
			if [[ "$oldrest" == "$rest" ]]; then
echo :--Mistake--:
#				sleep 0.01
#				rest=${rest% *}
#				if [[ "$oldrest" == "$rest" ]]; then
#					echo 'unable to interpret'
#					echo
#					return
#				fi
			fi
		else
			before=$rest\ 
		fi
	done
	echo
}
bb 'mplayer \[Commie\]\ Vividred\ Operation\ -\ 03\ \[D3429195\].'
echo
bb 'mplayer \[Commie\]\ Vividred\ Operation\ -\ 04\ '
echo
#bb 'mplayer \[Commie\]\ Ore\ no\ Kanojo\ to\ Osananajimi\ ga\ Shuraba\ Sugiru\ -\ My\ Girlfriend\ and\ Childhood\ Friend\ Fight\ Too\ Much\ -\ 01\ \[1C42F3FD\]'
#echo
#bb 'mplayer \[Commie\]\ Ore\ no\ Kanojo\ to\ Osananajimi\ ga\ Shuraba\ Sugiru\ -\ My\ Girlfriend\ and\ Childhood\ Friend\ Fight\ Too\ Much\ -\ 01\ '
#echo
#bb 'mplayer \[Commie\]\ Ore\ no\ Kanojo\ to\ Osananajimi\ ga\ Shuraba\ Sugiru\ -\ My\ Girlfriend\ and\ Childhood\ Friend\ Fight\ Too\ Much\ -\ 0'
#echo
#bb 'mplayer \[Commie\]\ Ore\ no\ Kanojo\ to\ Osananajimi\ ga\ Shuraba\ Sugiru\ -\ My\ Girlfriend\ and\ Childhood\ Friend\ Fight\ Too\ Much'
#echo
[[ $1 ]] && bb "$1"

Not that it will go into an infinite loop if there's no non-escaped space.
If it echoes "Mistake" that means rest=${rest% *} didn't do anything and that means the last word in $rest will be appended another time to $last. It usually works after a few times.
Example output in the final run:

REST:mplayer:
LAST:\[Commie\]\ Vividred\ Operation\ Operation\ Operation\ -\ -\ -\ -\ -\ -\ 04\ 04\ 04\ 04\ 04\ 04\ :

This means ${variable%...} is broken.

Any ideas what this could be or should I contact the bash devs?

Last edited by Procyon (2013-02-12 17:31:10)

Offline

#143 2013-03-16 12:52:00

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

Re: Kingbash - menu driven auto-completion

The new bash version is out, so I'll make an update soon. Lately I've been having trouble with CTRL+C on certain programs launched from a line made with tab-completion. I have no idea what causes this because stty -g and restoring it causes lots of other problems. I'll try to make it a script again.

I've had two options kind of tagged on: the help bar and directories first. Keep them like they are?

Offline

#144 2013-03-16 21:02:14

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

Re: Kingbash - menu driven auto-completion

Okay, I think it's ready. Please try it out.

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

Because it's a function now, you need to pass compgen -A alias -A function to get completion for those commands.

You can add or replace "dirfirst" to "nohelp" if you want.

Offline

#145 2013-03-18 08:08:25

kokoko3k
Member
Registered: 2008-11-14
Posts: 1,445

Re: Kingbash - menu driven auto-completion

I'm using it right now, seems to run without issues smile

Offline

#146 2013-03-23 17:33:53

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

Re: Kingbash - menu driven auto-completion

That's good to hear. I'll update the AUR now.

Offline

#147 2013-05-04 11:50:29

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

Re: Kingbash - menu driven auto-completion

I discovered that tmux does support line wrap stop, it's just that tput rmam doesn't know the control code when inside tmux.
It works with echo -ne '\e[?7l' and it's the same code for urxvt and xterm.

kingbash:

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

kbdmenu:

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

Offline

#148 2014-01-27 16:09:07

eMPee584
Member
Registered: 2014-01-27
Posts: 2

Re: Kingbash - menu driven auto-completion

Dear Procyon,
thx for coding this up, it's what I failed quite miserably at on stereoidz ×-D

Procyon wrote:

curl 'http://pastebin.com/raw.php?i=xY6hBVxf' | sed 's/\r$//' > kingbash.script
curl 'http://pastebin.com/raw.php?i=gMe6jvjk' | sed 's/\r$//' > kbdmenu

Would it be possible for you to create a repository on github? This would allow easier tracking of changes, packaging in other distros, issue tracking and distributed development...
#bestRegards

Offline

#149 2014-01-28 20:44:39

eMPee584
Member
Registered: 2014-01-27
Posts: 2

Re: Kingbash - menu driven auto-completion

Ok, I imported all the bash releases of Procyon's script into a git repo which is to be found at:
https://github.com/eMPee584/kingbash
@Procyon
I will gladly transfer it to you if you want to maintain it. I couldn't find a public mail address of yours, if you tell me I can add it to the commits.
#best.

Offline

#150 2014-01-29 12:00:19

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

Re: Kingbash - menu driven auto-completion

If you can maintain that then that would be fine with me. Maybe use a kingbash screenshot instead of kingcon and the readme needs the bind -x command example.

Because I don't really see many updates coming anymore, and so I'll also just keep posting in this thread so it's easier for me. There are a few bugs left (like with F3 / time sort, and escaping out of line with backslashes can cause double backslashes), but I haven't been bothered to fix them. For (my) normal usage I think it's just fine as it is now and I'm really happy with it. Maybe if people have feature requests or my usage patterns change, then I'll work on it again.

Offline

Board footer

Powered by FluxBB