diff options
author | 2011-01-11 23:22:27 +1100 | |
---|---|---|
committer | 2011-01-11 23:22:27 +1100 | |
commit | 2583638f4bb0b1b46f82f6ed2320a644f2c8e64b (patch) | |
tree | 54b3f58d19ea5519402472a14e740e31f27bfa81 | |
parent | dcecab384acc003beb43859ee2143c9b78795d55 (diff) | |
parent | 11360b018fd797a60705b0aa74c8001d006562ed (diff) |
Merge commit 'refs/merge-requests/8' of git://gitorious.org/fish-shell/fish-shell into merge_request_8
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | builtin.c | 4 | ||||
-rw-r--r-- | fish_indent.c | 77 | ||||
-rw-r--r-- | mimedb.c | 95 | ||||
-rw-r--r-- | share/functions/__fish_print_packages.fish | 12 | ||||
-rw-r--r-- | share/functions/fish_default_key_bindings.fish | 2 | ||||
-rw-r--r-- | share/functions/funcsave.fish | 10 |
7 files changed, 143 insertions, 59 deletions
diff --git a/Makefile.in b/Makefile.in index 2f09833d..32dc2bb7 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 @@ -2070,7 +2070,7 @@ static int builtin_read( wchar_t **argv ) } , { - L"shell", required_argument, 0, 's' + L"shell", no_argument, 0, 's' } , { @@ -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" ); } diff --git a/fish_indent.c b/fish_indent.c index 5e709f2b..14cf5a6c 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--; @@ -132,7 +137,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 ); } @@ -144,7 +149,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 +168,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 +231,6 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags ) break; } - case TOK_COMMENT: { if( do_indent && flags) @@ -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; } @@ -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; @@ -285,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; @@ -297,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 { @@ -309,23 +323,27 @@ 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); - if (result) - return result; + if ( result ) + { + al_push( list, result ); + if ( !all ) + return 1; + } } } 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; @@ -345,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; @@ -359,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; } /** @@ -638,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 ) { @@ -717,7 +762,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 ) { diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index 8dae87b9..1991bd6d 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 diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index f8e1edf4..a26387d4 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 diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish index ff9cabb5..a1725ca9 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 |