From 081e277fe4ce510687405d1b0ef71041a282e02d Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Thu, 25 Nov 2010 19:09:31 +0800 Subject: [PATCH 01/12] builtin: read's --shell long option should require an argument The short option -s doesn't need it and it won't be used. Signed-off-by: Grissiom --- builtin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin.c b/builtin.c index 13694aacb..a90e14c03 100644 --- a/builtin.c +++ b/builtin.c @@ -2070,7 +2070,7 @@ static int builtin_read( wchar_t **argv ) } , { - L"shell", required_argument, 0, 's' + L"shell", no_argument, 0, 's' } , { From 4ccf26fbcc3bfd27ed2f1638254bd9f4b92dbd52 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 26 Nov 2010 19:00:18 +0800 Subject: [PATCH 02/12] builtin: count should not accept options, not even help It is documented this way, but the common builtin_run function was checking for -h or --help before even calling the builtin_count. Without this functions like funced can't use count to check the number of arguments before checking for -h or --help. Signed-off-by: Grissiom --- builtin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin.c b/builtin.c index a90e14c03..41a952602 100644 --- a/builtin.c +++ b/builtin.c @@ -3871,7 +3871,7 @@ static int internal_help( wchar_t *cmd ) { CHECK( cmd, 0 ); return contains( cmd, L"for", L"while", L"function", - L"if", L"end", L"switch" ); + L"if", L"end", L"switch", L"count" ); } From df23913bb8c38f2286497dde5cc65798ce9d4473 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Wed, 1 Dec 2010 13:05:10 +0800 Subject: [PATCH 03/12] fish_indent: only output fd number when have to The original patch is own by Dylan. I just did some cleaning and reformating. --- fish_indent.c | 72 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/fish_indent.c b/fish_indent.c index 5e709f2b8..31807e816 100644 --- a/fish_indent.c +++ b/fish_indent.c @@ -144,7 +144,9 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) } else { - sb_printf( out, L" %ls", last ); + if ( prev_type != TOK_REDIRECT_FD ) + sb_append( out, L" " ); + sb_append( out, last ); } break; @@ -161,39 +163,60 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) case TOK_PIPE: { - sb_append( out, L" | " ); + sb_append( out, L" " ); + if ( last[0] == '2' && !last[1] ) { + sb_append( out, L"^" ); + } else if ( last[0] != '1' || last[1] ) { + sb_append( out, last, L">" ); + } + sb_append( out, L"| " ); is_command = 1; break; } case TOK_REDIRECT_OUT: - case TOK_REDIRECT_APPEND: - case TOK_REDIRECT_IN: - case TOK_REDIRECT_FD: { - sb_append( out, last ); - switch( type ) - { - case TOK_REDIRECT_OUT: - sb_append( out, L"> " ); - break; - - case TOK_REDIRECT_APPEND: - sb_append( out, L">> " ); - break; - - case TOK_REDIRECT_IN: - sb_append( out, L"< " ); - break; - - case TOK_REDIRECT_FD: - sb_append( out, L">& " ); - break; - + sb_append( out, L" " ); + if ( wcscmp( last, L"2" ) == 0 ) { + sb_append( out, L"^" ); + } else { + if ( wcscmp( last, L"1" ) != 0 ) + sb_append( out, last ); + sb_append( out, L">" ); } break; } + case TOK_REDIRECT_APPEND: + { + sb_append( out, L" " ); + if ( wcscmp( last, L"2" ) == 0 ) { + sb_append( out, L"^^" ); + } else { + if ( wcscmp( last, L"1" ) != 0 ) + sb_append( out, last ); + sb_append( out, L">>" ); + } + break; + } + + case TOK_REDIRECT_IN: + { + sb_append( out, L" " ); + if ( wcscmp( last, L"0" ) != 0 ) + sb_append( out, last ); + sb_append( out, L"<" ); + break; + } + + case TOK_REDIRECT_FD: + { + sb_append( out, L" " ); + if ( wcscmp( last, L"1" ) != 0 ) + sb_append( out, last ); + sb_append( out, L">&" ); + break; + } case TOK_BACKGROUND: { @@ -203,7 +226,6 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) break; } - case TOK_COMMENT: { if( do_indent && flags) From f2ad4a2e8e502091651d1d9861169e31b927ed01 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 26 Nov 2010 15:16:56 -0500 Subject: [PATCH 04/12] Makefile: test for xsel directory before trying to clean it. This avoids the users seeing ignored errors for make -C clean. --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 2f09833da..32dc2bb70 100644 --- a/Makefile.in +++ b/Makefile.in @@ -887,7 +887,7 @@ clean: rm -rf doc; rm -rf fish-@PACKAGE_VERSION@ rm -f $(TRANSLATIONS) - -make -C $(XSEL) clean + test ! -d "$(XSEL)" || make -C $(XSEL) clean .PHONY: clean From 164144f1265b26446eafa16091e0eed9e2344a9d Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Wed, 24 Nov 2010 15:15:10 -0500 Subject: [PATCH 05/12] default_key_bindings: Added mappings for ctrl-arrow keys. On debian and ubuntu these control sequences are output while using gnome-terminal and xterm. --- share/functions/fish_default_key_bindings.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index f8e1edf49..a26387d40 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -68,6 +68,8 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis bind \e\x7f backward-kill-word bind \eb backward-word bind \ef forward-word + bind \e\[1\;5C forward-word + bind \e\[1\;5D backward-word bind \ed forward-kill-word bind -k ppage beginning-of-history bind -k npage end-of-history From fd4ac87382a4873df649cdacf1c65155cb9b2c4d Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Sat, 20 Nov 2010 01:42:11 -0500 Subject: [PATCH 06/12] funcsave: Fixed error and help handling. Renamed references to the previous command name of save_function to funcsave, and returned an error after printing the help text when no arguments are specified. --- share/functions/funcsave.fish | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish index ff9cabb54..a1725ca9d 100644 --- a/share/functions/funcsave.fish +++ b/share/functions/funcsave.fish @@ -4,11 +4,13 @@ function funcsave --description "Save the current definition of all specified fu if count $argv >/dev/null switch $argv[1] case -h --h --he --hel --help - __fish_print_help save_function + __fish_print_help funcsave return 0 end else - __fish_print_help save_function + printf (_ "%s: Expected function name\n") funcsave + __fish_print_help funcsave + return 1 end set -l res 0 @@ -21,7 +23,7 @@ function funcsave --description "Save the current definition of all specified fu for i in $configdir $configdir/fish $configdir/fish/functions if not test -d $i if not command mkdir $i >/dev/null - printf (_ "%s: Could not create configuration directory\n") save_function + printf (_ "%s: Could not create configuration directory\n") funcsave return 1 end end @@ -32,7 +34,7 @@ function funcsave --description "Save the current definition of all specified fu functions $i > $configdir/fish/functions/$i.fish functions -e $i else - printf (_ "%s: Unknown function '%s'\n") save_function $i + printf (_ "%s: Unknown function '%s'\n") funcsave $i set res 1 end end From cf0850edfd5cb7188a6b6f36ce277cd4619a91b2 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 26 Nov 2010 11:25:30 -0500 Subject: [PATCH 07/12] mimedb: Add seperator between directory and filename in file_exists. get_filename tried to work around this with hardcoded strings that end with a '/', but would fail to work properly for environment variables XDG_DATA_HOME or XDG_DATA_DIRS that don't do the same. --- mimedb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mimedb.c b/mimedb.c index b62d4ebb4..11c325000 100644 --- a/mimedb.c +++ b/mimedb.c @@ -240,7 +240,9 @@ static char * search_ini( const char *filename, const char *match ) */ static char *file_exists( const char *dir, const char *in ) { - char *filename = my_malloc( strlen( dir ) + strlen(in) + 1 ); + int dir_len = strlen( dir ); + int need_sep = dir[dir_len - 1] != '/'; + char *filename = my_malloc( dir_len + need_sep + strlen( in ) + 1 ); char *replaceme; struct stat buf; @@ -251,7 +253,9 @@ static char *file_exists( const char *dir, const char *in ) return 0; } strcpy( filename, dir ); - strcat( filename, in ); + if ( need_sep ) + filename[dir_len++] = '/'; + strcpy( filename + dir_len, in ); if( !stat( filename, &buf ) ) return filename; @@ -309,12 +313,12 @@ static char *get_filename( char *f ) { char *guessed_xdg_home; - guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share/") + 1); + guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share") + 1); if( !guessed_xdg_home ) return 0; strcpy (guessed_xdg_home, home); - strcat (guessed_xdg_home, "/.local/share/"); + strcat (guessed_xdg_home, "/.local/share"); result = file_exists( guessed_xdg_home, f ); free (guessed_xdg_home); @@ -325,7 +329,7 @@ static char *get_filename( char *f ) xdg_data_dirs = getenv ("XDG_DATA_DIRS"); if (xdg_data_dirs == NULL) - xdg_data_dirs = "/usr/local/share/:/usr/share/"; + xdg_data_dirs = "/usr/local/share:/usr/share"; ptr = xdg_data_dirs; From 6a5d6471c5493269d057d0b9d1f59ba18753c1da Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 26 Nov 2010 11:28:51 -0500 Subject: [PATCH 08/12] mimedb: Search for exact mime type match in search_ini. --- mimedb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mimedb.c b/mimedb.c index 11c325000..0572023b3 100644 --- a/mimedb.c +++ b/mimedb.c @@ -214,7 +214,7 @@ static char * search_ini( const char *filename, const char *match ) buf[0]=0; done = 1; } - else if( strncmp( buf, match,len )==0) + else if( strncmp( buf, match, len ) == 0 && buf[len] == '=' ) { done=1; } @@ -721,7 +721,7 @@ static char *get_action( const char *mimetype ) free( launcher_full ); - launcher_command_str = search_ini( launcher_filename, "Exec=" ); + launcher_command_str = search_ini( launcher_filename, "Exec" ); if( !launcher_command_str ) { From 46986ad4c27420e7edcbff10490694fe56f12de2 Mon Sep 17 00:00:00 2001 From: James Bowlin Date: Thu, 2 Dec 2010 01:33:56 +0800 Subject: [PATCH 09/12] Use eix instead of emerge when possible On Gentoo the eix program is MUCH faster than emerge for listing package names. I've left the emerge code in as a 2nd choice because not every Gentoo system has eix installed (although they should). Also, the emerge code didn't seem to produce any output on my system. Signed-off-by: Grissiom --- share/functions/__fish_print_packages.fish | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 8dae87b91..1991bd6d7 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -46,9 +46,17 @@ function __fish_print_packages # This completes the package name from the portage tree. # True for installing new packages. Function for printing # installed on the system packages is in completions/emerge.fish - if type -f emerge >/dev/null - emerge -s \^(commandline -tc) |sgrep "^*" |cut -d\ -f3 |cut -d/ -f2 + + # eix is MUCH faster than emerge so use it if it is available + if type -f eix > /dev/null + eix --only-names "^"(commandline -tc) | cut -d/ -f2 return + else + # FIXME? Seems to be broken + if type -f emerge >/dev/null + emerge -s \^(commandline -tc) |sgrep "^*" |cut -d\ -f3 |cut -d/ -f2 + return + end end end From 74f06d550a4c2e4260a6c1f1db58260069be3904 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 2 Dec 2010 23:42:24 +0800 Subject: [PATCH 10/12] fish_indent: don't indent commands after a pipe commands after a pipe tend to be at the same line of previous command. So don't indent them. --- fish_indent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_indent.c b/fish_indent.c index 31807e816..f3184c4c4 100644 --- a/fish_indent.c +++ b/fish_indent.c @@ -132,7 +132,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) } - if( do_indent && flags) + if( do_indent && flags && prev_type != TOK_PIPE ) { insert_tabs( out, indent ); } From bdfc62184d303a3bdcea7f500bd8a8b2b8a3b7ed Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 2 Dec 2010 23:42:48 +0800 Subject: [PATCH 11/12] fish_indent: indent "case" with the same level as "swith" --- fish_indent.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fish_indent.c b/fish_indent.c index f3184c4c4..14cf5a6cf 100644 --- a/fish_indent.c +++ b/fish_indent.c @@ -125,6 +125,11 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) { indent--; } + /* case should have the same indent level as switch*/ + else if( wcscmp( unesc, L"case" ) == 0 ) + { + indent--; + } else if( wcscmp( unesc, L"end" ) == 0 ) { indent--; From 11360b018fd797a60705b0aa74c8001d006562ed Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 26 Nov 2010 13:46:54 -0500 Subject: [PATCH 12/12] mimedb: Search all the defaults.list files rather than just the first. The first defaults.list file found should not override all the other ones, it just needs to be searched first. E.g. For me (cat ~/.local/share/applications/defaults.list) returns [Default Applications] text/html=chromium-browser.desktop So this should be used for text/html mimetypes, but the other defaults.list files should be searched for other mimetypes. I had to refactor get_filename so that it can return all the filenames, so I changed it to append_filenames that appends all the filenames to a list and provided a wrapper function called get_filename. --- mimedb.c | 77 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/mimedb.c b/mimedb.c index 0572023b3..00148e0ba 100644 --- a/mimedb.c +++ b/mimedb.c @@ -289,9 +289,15 @@ static char *file_exists( const char *dir, const char *in ) Try to find the specified file in any of the possible directories where mime files can be located. This code is shamelessly stolen from xdg_run_command_on_dirs. + + \param list Full file paths will be appended to this list. + \param f The relative filename search for the the data directories. + \param all If zero, then stop after the first filename. + \return The number of filenames added to the list. */ -static char *get_filename( char *f ) +static int append_filenames( array_list_t *list, char *f, int all ) { + int prev_count = al_get_count( list ); char *result; const char *xdg_data_home; const char *xdg_data_dirs; @@ -301,8 +307,12 @@ static char *get_filename( char *f ) if (xdg_data_home) { result = file_exists( xdg_data_home, f ); - if (result) - return result; + if ( result ) + { + al_push( list, result ); + if ( !all ) + return 1; + } } else { @@ -322,8 +332,12 @@ static char *get_filename( char *f ) result = file_exists( guessed_xdg_home, f ); free (guessed_xdg_home); - if (result) - return result; + if ( result ) + { + al_push( list, result ); + if ( !all ) + return 1; + } } } @@ -349,10 +363,7 @@ static char *get_filename( char *f ) continue; } - if (*end_ptr == ':') - len = end_ptr - ptr; - else - len = end_ptr - ptr + 1; + len = end_ptr - ptr; dir = my_malloc (len + 1); if( !dir ) return 0; @@ -363,12 +374,32 @@ static char *get_filename( char *f ) free (dir); - if (result) - return result; + if ( result ) + { + al_push( list, result ); + if ( !all ) { + return 1; + } + } ptr = end_ptr; } - return 0; + return al_get_count( list ) - prev_count; +} + +/** + Find at most one file relative to the XDG data directories. +*/ +static char *get_filename( char *f ) +{ + array_list_t list; + char *first = NULL; + + al_init( &list ); + append_filenames( &list, f, 0 ); + first = al_pop( &list ); + al_destroy( &list ); + return first; } /** @@ -642,22 +673,32 @@ static char *get_description( const char *mimetype ) static char *get_action( const char *mimetype ) { char *res=0; + int i; char *launcher; char *end; - char *mime_filename; + array_list_t mime_filenames; - char *launcher_str; + char *launcher_str = NULL; char *launcher_filename, *launcher_command_str, *launcher_command; char *launcher_full; - mime_filename = get_filename( DESKTOP_DEFAULT ); - if( !mime_filename ) + al_init( &mime_filenames ); + if( !append_filenames( &mime_filenames, DESKTOP_DEFAULT, 1 ) ) + { + al_destroy( &mime_filenames ); return 0; + } - launcher_str = search_ini( mime_filename, mimetype ); + for ( i = 0; i < al_get_count( &mime_filenames ); i++ ) + { + launcher_str = search_ini( al_get( &mime_filenames, i ), mimetype ); + if ( launcher_str ) + break; + } - free( mime_filename ); + al_foreach( &mime_filenames, free ); + al_destroy( &mime_filenames ); if( !launcher_str ) {