Compare commits

...

908 Commits

Author SHA1 Message Date
ridiculousfish
5827bfd9a2 Default fish_pager_color_description to '555 yellow'
Fixes https://github.com/fish-shell/fish-shell/issues/280
2012-11-18 03:17:51 -08:00
ridiculousfish
dc8cc39bc8 Don't autosuggest in builtin_read
https://github.com/fish-shell/fish-shell/issues/29
2012-11-18 02:43:35 -08:00
ridiculousfish
c9c2fc5ee3 Restore terminal foreground process group on exit
Fixes https://github.com/fish-shell/fish-shell/issues/197
2012-11-18 02:16:14 -08:00
Terje Larsen
b79854ad1a Optimize staged logic 2012-11-17 13:37:32 -08:00
Terje Larsen
8229b17f0d Use double-dollar vars for dynamic variables 2012-11-17 13:37:32 -08:00
Terje Larsen
4a5d02aab4 Add configurable status signs again 2012-11-17 13:37:32 -08:00
Terje Larsen
ed4e6cd3a5 Fix uniqueness and escape question-marks 2012-11-17 13:37:32 -08:00
Sławek Piotrowski
7d45e6f12f Fix: args -> argv in __fish_git_prompt 2012-11-14 19:00:17 +01:00
ridiculousfish
0302162d8e Make tab-completion truncation less dumb
Fixes https://github.com/fish-shell/fish-shell/issues/259
2012-11-09 16:02:19 -08:00
ridiculousfish
1dfa404210 Revert "Another attempt to improve right prompt on Linux"
It didn't work

This reverts commit bd4551e2ef.
2012-11-09 15:21:08 -08:00
ridiculousfish
bd4551e2ef Another attempt to improve right prompt on Linux 2012-11-09 15:19:54 -08:00
ridiculousfish
d6a56428d1 Attempt to fix fish_right_prompt under Linux 2012-11-09 15:09:54 -08:00
David Adam (zanchey)
a10fa3a20b add $FISH_VERSION as unexported global variable to complement version 2012-11-08 10:09:51 -08:00
David Adam (zanchey)
be5fde9e54 test documentation - format examples properly 2012-11-08 10:08:06 -08:00
David Adam (zanchey)
abfc7e16a1 test documentation - correct argument listing 2012-11-08 10:08:06 -08:00
ridiculousfish
d76f880faf Support for fish_right_prompt
Fixes https://github.com/fish-shell/fish-shell/issues/80
2012-11-07 19:59:20 -08:00
ridiculousfish
21e83a881e Bring back ellipsis 2012-11-05 00:05:42 -08:00
ridiculousfish
5ba1261285 Initial right_prompt work 2012-11-04 23:21:37 -08:00
ridiculousfish
7bb844a778 Fix bug where 'else if' does not support functions and redirections
https://github.com/fish-shell/fish-shell/issues/359
2012-11-04 17:11:02 -08:00
ridiculousfish
8c24d49c73 Removed unused commented out code and fixed some indentation 2012-11-04 15:47:55 -08:00
ridiculousfish
5e371e8fe7 Don't use posix_spawn for commands that need to be put into foreground to avoid a race
Fix for race where a command's output may not be fully drained
2012-11-04 15:45:52 -08:00
ridiculousfish
e46324ced9 Wrong sense of check for initializing key bindings
Fix for https://github.com/fish-shell/fish-shell/pull/373
2012-10-30 14:36:37 -07:00
ridiculousfish
5ea486b20a Fix help completion to not barf if html file is absent 2012-10-29 01:53:10 -07:00
ridiculousfish
425afa63ce Don't use posix_spawn when file redirections are involved (except /dev/null) because the error handling is too difficult
Fix exec to correctly handle the case where a pid could not be created due to posix_spawn failing
Should fix https://github.com/fish-shell/fish-shell/issues/364
2012-10-29 01:45:51 -07:00
ridiculousfish
7c09a767b6 Don't expand jobs during syntax highlighting
Fixes https://github.com/fish-shell/fish-shell/issues/366
2012-10-28 16:35:17 -07:00
Siteshwar Vashisht
768f92303e Removed python scripts to import bash settings 2012-10-27 23:57:15 +05:30
ridiculousfish
34054fa1fb Merge pull request #362 from terlar/git-completions
Git completions
2012-10-25 18:56:59 -07:00
Terje Larsen
4a37d6d1f9 Remove remotes prefix from branches 2012-10-22 20:54:33 +02:00
Terje Larsen
8dfc8625a7 Add git completions for tracking (branch/checkout) 2012-10-22 20:50:38 +02:00
Terje Larsen
e878947cb2 Fix broken git alias completion
The previous command outputs a lot of junk, does not strip after the
white-space in OSX (10.8.2).

Tried out the new command on both Ubuntu (12.04.1) and OSX (10.8.2)
2012-10-22 20:37:47 +02:00
Terje Larsen
f56f84c6ac Use echo -n instead of printf
- Remove useless comment, because multi-line prompt works good now.
2012-10-20 12:52:53 -07:00
Terje Larsen
239d43dac4 Improve the git prompt
- Fix branch for older git version (--short for symbolic-ref was not
  available on git 1.7.9.5)
- Use index (git status) for checking if staged
- Add status indication for copied
- Remove variables for statuses (less litter in the variables)
- Remove usage of eval to echo and set_color
- Replace printf where possible with echo -n
2012-10-20 12:52:53 -07:00
ridiculousfish
8a63326411 Removed backwards compatibility check for fish_user_keybindings 2012-10-20 12:21:41 -07:00
Nate Soares
01608cf062 Normalized some inconsistent whitespace. 2012-10-20 12:15:49 -07:00
Nate Soares
e06d6ce4a2 Revive support for fish_user_keybindings
This is undocumented and here to preserve backwards compatibility.
2012-10-20 12:15:49 -07:00
Nate Soares
58a0c6f9d3 added missing underscore 2012-10-20 12:15:49 -07:00
Nate Soares
f310f1e96c keybindings → key_bindings (for consistency) 2012-10-20 12:15:49 -07:00
ridiculousfish
c7bf1aa222 Handle some more escapes in de-groffing man pages
Fixes https://github.com/fish-shell/fish-shell/issues/10
2012-10-17 18:22:57 -07:00
Adrien
be3fff9282 Add apt-cache completion for package names
Signed-off-by: Gustavo Noronha Silva <kov@kov.eti.br>
2012-10-17 18:05:49 -07:00
ridiculousfish
e52cf09bc1 Simplify handling of escape sequences in echo -e 2012-10-17 17:08:45 -07:00
ridiculousfish
57de1388e8 Make the \c special character in echo suppress the newline too 2012-10-17 02:59:43 -07:00
ridiculousfish
7ee0ce745e Implement -e option to echo (to interpret special characters), and -E to not interpret them
https://github.com/fish-shell/fish-shell/issues/337
2012-10-17 02:56:03 -07:00
ridiculousfish
469743cd23 Made set_color with no arguments not complain, so that prompts like Terlar don't produce errors for missing colors. 2012-10-17 01:25:21 -07:00
ridiculousfish
91e1d59869 Fix for issue where else if would fail to pass arguments to commands. Also implements short-circuiting for and/or so that non-existent commands don't produce error messages.
Fixes https://github.com/fish-shell/fish-shell/issues/345
Fixes https://github.com/fish-shell/fish-shell/issues/349
2012-10-17 01:07:34 -07:00
ridiculousfish
5fb97f05a3 Fixed "Expansion not correctly handling literal path components in dotfiles" test 2012-10-16 11:51:36 -07:00
ridiculousfish
618b42980d Prevent multi-line prompts from repeating during window resize
Fixes https://github.com/fish-shell/fish-shell/issues/321
2012-10-15 19:25:56 -07:00
ridiculousfish
211b9ea8b9 Added terlar's prompt, and robbyrussell which was inadvertently omitted
https://github.com/fish-shell/fish-shell/issues/329
2012-10-15 18:45:46 -07:00
ridiculousfish
833abc27cc Make wildcards beginning with dots not match . and ..
https://github.com/fish-shell/fish-shell/issues/270
2012-10-15 18:16:47 -07:00
ridiculousfish
3d5a3f03fa Fix to prevent buff_pos from underflowing in reader_kill 2012-10-08 23:47:32 -07:00
ridiculousfish
51de26960c Make escaping consistent for fish <-> fishd protocol
Fix fork guards to work in fishd
https://github.com/fish-shell/fish-shell/issues/339
2012-10-08 14:47:25 -07:00
ridiculousfish
b67526aae8 Don't reset the terminal mode in certain circumstances. Fixes issue in Linux with e.g. echo foo ; ftp
Introduce patch from 9d229cd18c
2012-10-05 18:23:38 -07:00
ridiculousfish
14bf057c62 Remove bogus path from example of "." (source) command
https://github.com/fish-shell/fish-shell/issues/297
2012-10-04 14:57:23 -07:00
ridiculousfish
8eb53ea7ca Rewrite kill behavior (aka control-W) to do something better
Fixes https://github.com/fish-shell/fish-shell/issues/327
2012-10-04 14:35:03 -07:00
ridiculousfish
9b60af4d52 Fix to propagate the last color before highlighting completes, and to avoid repainting when highlighting completes if the color does not change 2012-10-03 12:19:27 -07:00
SanskritFritz
956f99365a Some new completions and modified some others. 2012-10-02 17:54:30 -07:00
SanskritFritz
9904415144 Facelift for pacman completions. 2012-10-02 17:54:30 -07:00
SanskritFritz
83febbdc7d Package groups were completed as repos. Fixed.
By default fish expands arguments along with options. This is not desired,
so made sure they are expanded only when needed, for performance reasons.
2012-10-02 17:54:30 -07:00
ridiculousfish
6b026e399c Prevent some cases where garbage gets dumped on the screen during window resize under new soft wrapping architecture 2012-10-02 17:30:07 -07:00
ridiculousfish
a661c03743 Work on soft wrapping to address https://github.com/fish-shell/fish-shell/issues/300
Resizing is still wonky
2012-10-01 03:29:18 -07:00
Ian Munsie
ffc03735e8 Don't barf when ending a FAKE block
After updating, fish would immediately die when started in an xterm from
my window manager (wmii) with a message like:

fish: builtin.cpp:3357: int builtin_end(parser_t&, wchar_t**): Assertion `false' failed.
fish: Job 1, “~/code/fish-shell/fish” terminated by signal SIGABRT (Abort)

Starting fish from an existing shell worked, and running it on other
machines that I was only SSHing into worked as well. I did discover that
on one machine starting git from one specific directory
(/home/ian/bml/kernel) would cause this failure, but starting from any
other directory worked as normal. I'm not entirely sure what
circumstances contribute to this failure - starting from a copy of the
kernel directory works fine.

The failure only started with the following commit, which introduced the
assert(false):

commit d788c84440
Made type property of block_t constant and private
Further work towards cleaning up block_t hierarchy

Looking at this fail in gdb:

(gdb) r
Starting program: /home/ian/code/fish-shell/fish
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
fish: builtin.cpp:3357: int builtin_end(parser_t&, wchar_t**): Assertion `false' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff6c82475 in *__GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
    function=0x548520 "int builtin_end(parser_t&, wchar_t**)") at assert.c:81
(gdb) up 3
3357                    assert(false); //should never get here
(gdb) p parser.current_block->type()
$1 = FAKE

So this happens when we run an end command for a FAKE block.

The below patch adds an empty case for FAKE blocks to avoid hitting the
assert. I would need to study the code in more detail to understand if
we should even be executing this code if we are in a FAKE block, but
this patch seems to solve the issue for me.

Signed-off-by: Ian Munsie <darkstarsword@gmail.com>
2012-09-22 23:51:41 -07:00
maxfl
c7e24488eb fix output 2012-09-22 23:49:26 -07:00
maxfl
fe7d2c57e3 nmcli completions 2012-09-22 23:49:26 -07:00
Siteshwar Vashisht
4fc80b5057 Fix for displaying multiline prompts 2012-09-20 00:47:31 +05:30
Siteshwar Vashisht
12f3f5dcbb Print autocompletion description after installing
Print autocompletion shortcut description at end of 'make install'
2012-09-19 13:21:49 +05:30
Siteshwar Vashisht
16f2ffc29d Remove ellipsis and newlines from long lines
Fix for issue https://github.com/fish-shell/fish-shell/issues/300
2012-09-18 00:42:11 +05:30
Peter Ammon
86a978d9ee Fixed web_config prompt to work with Python 2.6.1 2012-09-10 02:11:06 -07:00
ridiculousfish
f6fe3df59b Fix to make prompt chooser work in Python3 2012-09-06 19:01:07 -07:00
ridiculousfish
e0764bb25e Improve python3 compatibility in webconfig.py 2012-09-06 02:03:21 -07:00
ridiculousfish
1ba0bfd10c Renamed hyperminamlist prompt 2012-09-06 01:52:21 -07:00
ridiculousfish
593ab75a76 Fix to make Makefile copy sample prompts 2012-09-06 01:40:15 -07:00
ridiculousfish
3589554028 Allow setting the prompt from web_config 2012-09-06 01:30:26 -07:00
ridiculousfish
1a59346b51 Changed "elseif" to "else if" 2012-09-03 13:24:01 -07:00
ridiculousfish
ff124465fd Clean up some warnings and some unused if-related code 2012-09-01 12:29:00 -07:00
ridiculousfish
de5223db66 Improve documentation and error reporting for elseif. 2012-09-01 02:14:13 -07:00
ridiculousfish
cc1395797e First stab at elseif implementation 2012-09-01 01:46:14 -07:00
Torsten Grust
122791646e Fix check for non-empty argument (= initial tab) in fish_config
The original version (based on 'test') was creating spurious files named "0" in the current working directory
2012-08-30 13:17:32 +02:00
ridiculousfish
a3c4de52d6 Fix braces style 2012-08-26 23:34:34 -07:00
ridiculousfish
95de6cf5a7 Migrated function_data_t out of base block class
Removed an auto_ptr (yay)
2012-08-26 23:30:23 -07:00
ridiculousfish
d788c84440 Made type property of block_t constant and private
Further work towards cleaning up block_t hierarchy
2012-08-26 23:16:20 -07:00
ridiculousfish
96046ffd30 First stab at getting rid of the ugly state1, state2 properties of block_t 2012-08-26 22:42:29 -07:00
ridiculousfish
b5e92a831b Use xdg-open instead of BROWSER, if available
https://github.com/fish-shell/fish-shell/issues/293
2012-08-25 13:02:58 -07:00
maxfl
a2788129ff Minor updates
* Add -L/--long completion for 'set' command.
* Fix completion description color.
2012-08-25 00:54:47 -07:00
ridiculousfish
5bbf220077 Fix bug where underlining was failing for paths prefixed with ~
Fixes https://github.com/fish-shell/fish-shell/issues/292
2012-08-23 11:21:35 -07:00
ridiculousfish
f5d4e3f94c Reintroduce IO transmorgrification (yuck) to fix problems with fish_config and complicated IO redirections 2012-08-22 13:41:21 -07:00
ridiculousfish
04ea680e9a Support for tab cyling through completions
https://github.com/fish-shell/fish-shell/issues/84
2012-08-21 17:18:52 -07:00
ridiculousfish
3a940781d9 Replaced README with README.md for github
Changed 'root' Xcode target to 'install_tree' to avoid confusion
2012-08-21 02:08:49 -07:00
ridiculousfish
00fcd63b88 Clean up fish.app target to build correctly. Still won't run from Xcode, but will run from Finder 2012-08-21 01:20:19 -07:00
ridiculousfish
f3093649de Improve Xcode build process to provide a real target for xcodebuild install 2012-08-20 23:50:11 -07:00
ridiculousfish
670e33ab27 Properly handle empty completions (e.g. tab-complete 'foo' with extant files 'foo' and 'foobar' should offer both)
Fixes issue described in https://github.com/fish-shell/fish-shell/issues/290
2012-08-20 13:09:21 -07:00
ridiculousfish
3606664cf7 Merge branch 'webserver' of git://github.com/simukis/fish-shell into simukis-webserver
Conflicts:
	share/tools/web_config/webconfig.py
2012-08-20 12:03:39 -07:00
ridiculousfish
81f45208b0 Make history deletion from web config work properly with Unicode under both Python2 and Python3
Make the filter search field hide properly in tabs where it's non-functional
Fixes https://github.com/fish-shell/fish-shell/issues/265
2012-08-20 11:58:54 -07:00
ridiculousfish
9145d05397 Restore correct order of IO redirections
Fixes https://github.com/fish-shell/fish-shell/issues/281
2012-08-19 14:09:39 -07:00
Simonas Kazlauskas
ef566836c4 Wipe unnecessary as statement 2012-08-19 23:26:15 +03:00
Simonas Kazlauskas
10dfca1a75 Decode data in python3 – Fixes #265.
In both in python2 and python3 parse_qs expects str object. In
python2 it worked ok, because self.rfile was open in binary mode and
str in python2 is actually a string of bytes. However in python3 str is
actually string of unicode literals, not bytes and file was still open
in binary mode. Thus, deleting any file with non-ascii byte inside
filename failed in python3.

Also, cgi.parse_qs is deprecated and shouldn't be used.
2012-08-19 23:19:07 +03:00
Simonas Kazlauskas
b3e3f041fe Remove trailing spaces and replace tabs with spaces 2012-08-19 22:55:50 +03:00
ridiculousfish
e3ec361552 Fixed indentation in next_tab_stop 2012-08-17 17:41:55 -07:00
ridiculousfish
bfccc7133d Fix for issue where init_tabs can't be modified on NetBSD 2012-08-17 17:36:52 -07:00
ridiculousfish
f41a699f5d Fix to make the choose-a-port loop work correctly for webconfig.py under Python3 2012-08-17 01:14:05 -07:00
ridiculousfish
7d029778e6 Disable file completion descriptions per https://github.com/fish-shell/fish-shell/issues/279 2012-08-15 18:20:44 -07:00
ridiculousfish
26857fabdc Real fix for https://github.com/fish-shell/fish-shell/issues/278
We forget to set the parent group ID in posix_spawn (!)
2012-08-15 17:32:57 -07:00
ridiculousfish
a9b119833a Actually work around https://github.com/fish-shell/fish-shell/issues/278 2012-08-15 17:26:54 -07:00
ridiculousfish
c5ffe8a974 Temporary workaround for SIGTIN and SIGTOU unhappiness with posix_spawn
Fixes https://github.com/fish-shell/fish-shell/issues/278
2012-08-15 17:25:33 -07:00
ridiculousfish
df1b4e1f21 Fix for missing copy-files phase in Xcode build 2012-08-15 16:54:30 -07:00
ridiculousfish
61686aff34 Adopt posix_spawn (!)
Rewrite IO chains to be a vector of pointers, instead of a linked list
Removed io_transmogrify
2012-08-15 00:57:56 -07:00
Scott Leggett
ad6645c48d Implement completion for 'dd'.
Closes #267.
2012-08-12 22:05:12 +10:00
ridiculousfish
1e328c3546 Better handle symlink loops in recursive wildcards (**)
https://github.com/fish-shell/fish-shell/issues/268
2012-08-07 02:50:12 -07:00
ridiculousfish
0e2a625815 Added some limited support for autosuggesting processes 2012-08-07 00:01:48 -07:00
ridiculousfish
6eb66770a4 Fix to make completions non-authoritative by default, which is why unknown options were always colored like errors (e.g. --rebase) 2012-08-06 23:34:55 -07:00
ridiculousfish
84729c4dfa Additional warnings cleanup, effective C++ violations, dead code removal 2012-08-05 13:24:33 -07:00
ridiculousfish
8de8877c7c Fix OS X compilation 2012-08-05 12:05:05 -07:00
ridiculousfish
fdc6c3722a Fixed a bunch of clang analyzer warnings
Simplified some memory allocations by migrating to std::string
2012-08-05 12:01:53 -07:00
Siteshwar Vashisht
deca475972 Fixed compilation on Linux
Addresses issue https://github.com/fish-shell/fish-shell/issues/264
2012-08-05 18:37:51 +05:30
ridiculousfish
ba070e21e4 Fix for stack overflow when overflowing a line 2012-08-04 18:41:14 -07:00
ridiculousfish
35e9fd1bb0 Fix for weird issues when a line becomes very long introduced by my warning fixes 2012-08-04 18:32:15 -07:00
ridiculousfish
4906609dd9 Fix for assertion failure in syntax highlighting 2012-08-04 18:02:13 -07:00
ridiculousfish
682353f9cc Fix to restore an optimization from parse_util_get_line_from_offset in a more thread-safe way 2012-08-04 17:44:14 -07:00
ridiculousfish
25c6671a87 Fix for inability to go backwards through history 2012-08-04 16:06:40 -07:00
ridiculousfish
c67702a498 Cleaned up lots of typecasts, simplified some string handling 2012-08-04 15:11:43 -07:00
ridiculousfish
5880cd88c8 Switch from int cursor[2] to struct cursor { int x; int y; } 2012-08-04 13:54:20 -07:00
ridiculousfish
54ceb4211e Additional warning fixes and migration from int to size_t or long where appropriate 2012-08-04 13:47:56 -07:00
ridiculousfish
7a46227141 More warning fixes and switching from int to long or size_t 2012-08-04 13:02:44 -07:00
ridiculousfish
b904aa78e8 Additional warning cleanup and switching from int to size_t where appropriate 2012-08-04 11:34:45 -07:00
ridiculousfish
8185bee4b8 Lots of work towards making fish build without warnings on Mountain Lion, mostly in terms of using size_t instead of int 2012-08-04 11:34:45 -07:00
ridiculousfish
2e1b3325c6 Warning cleanup 2012-08-04 11:34:45 -07:00
Rubycut
1b8f1650dc explain how to load binds automatically 2012-08-04 11:32:04 -07:00
maxfl
1070b34996 Get rid of 'nothing appropriate' output when completing.
Add watch completion.
2012-08-04 11:20:03 -07:00
Anders Bergh
13b1b73c15 Replaced references to http://fishshell.org/ with http://ridiculousfish.com/shell/. 2012-08-01 18:09:50 +02:00
ridiculousfish
e1de72d0ac Merge pull request #251 from bpinto/rbenv
completion for rbenv
2012-07-28 17:50:27 -07:00
Bruno Pinto
dc837eb8a3 completion for rbenv 2012-07-28 13:45:47 -03:00
ridiculousfish
f6b76e6ecb Fix to allow specifying an initial tab in fish_config
For example, you can run "fish_config history"
2012-07-27 13:40:43 -07:00
ridiculousfish
e7cbcc83a4 Implemented history deletion from fish_config
Fixes https://github.com/fish-shell/fish-shell/issues/250
2012-07-27 00:31:00 -07:00
ridiculousfish
390700ca71 Merge pull request #249 from kballard/git_prompt_showupstream
Fix showupstream behavior in __fish_git_prompt
2012-07-27 00:26:23 -07:00
Kevin Ballard
b604321169 Fix showupstream behavior in __fish_git_prompt
The __fish_git_prompt_show_upstream helper function was inadvertently
looking at the misnamed variable __fish_git_prompt_show_upstream in some
cases, including when implementing the bash.showUpstream override.
Fixing the script to use __fish_git_prompt_showupstream triggered an
infinite loop because the --on-variable hook does not distinguish
between local and global variables.

Update the script to set a completely different local variable to
__fish_git_prompt_showupstream and to override this local variable for
bash.showUpstream.

Also update the code that looks at bash.showUpstream to also read
bash.showupstream, because the bash script appears to have a bug where
it looks for bash.showupstream despite documenting bash.showUpstream.
2012-07-26 15:32:27 -07:00
ridiculousfish
62c49f13ce Switch from std::list to std::vector in a few places to reduce compiled code size 2012-07-24 22:32:11 -07:00
Colin Woodbury
eba75dbc2e Fixed two small spelling mistakes
- Saw these during normal usage today.
  "parens" or "parenthesis" was spelled as "parans".
  Fixed two instances of this to "parenthesis".
2012-07-24 22:39:03 +09:00
Siteshwar Vashisht
32d2d0f0d0 Minor refactoring and fixed a bug in history function 2012-07-24 04:35:37 +05:30
maxfl
81e0342bf6 index range doc 2012-07-24 03:56:34 +05:30
ridiculousfish
56599621cc Make add-shell correctly handle /etc/shells files that do not end with newlines
Fixes https://github.com/fish-shell/fish-shell/issues/77
2012-07-22 17:00:44 -07:00
ridiculousfish
261bf12c91 Lots of miscellaneous cleanup. Unified the path_get_cd_path, path_allocate_cd_path, etc. functions 2012-07-20 22:11:05 -07:00
ridiculousfish
b08fb86637 Renamed env_vars to env_vars_snapshot_t
Cleanup of non-wcstring version of path_get_path
2012-07-20 20:39:31 -07:00
ridiculousfish
b290fd33b9 Switch to more uses of wcstokenizer from wcstok()
Work towards cleaning up path_get_path
2012-07-20 15:01:56 -07:00
ridiculousfish
966bbd476f Use weak linking of wcsdup and wcscasecmp on OS X
Fixes https://github.com/fish-shell/fish-shell/issues/240
2012-07-20 14:33:29 -07:00
Siteshwar Vashisht
cf9bfe9e66 Print fish prompt when command is longer than a line
Fix for https://github.com/fish-shell/fish-shell/issues/239
2012-07-21 00:24:48 +05:30
ridiculousfish
bb4a05032b Merge branch 'index_range' 2012-07-19 10:59:11 -07:00
ridiculousfish
7039e01136 Fixed fish_pager build on Xcode (it was building fish_indent instead. D'oh!) 2012-07-18 12:28:26 -07:00
ridiculousfish
e9f43f1097 Changes to make fish use the relocated fishd instead of the installed one, if it exists 2012-07-18 10:50:56 -07:00
ridiculousfish
150789690f Merge pull request #234 from maxfl/completions
pacmatic and dmesg completions
2012-07-18 10:49:28 -07:00
Siteshwar Vashisht
e284233013 Don't add space at the end of tab completion for cd
Fix for https://github.com/fish-shell/fish-shell/issues/235
2012-07-18 19:48:19 +05:30
ridiculousfish
d06d6c6964 Various changes to reduce fish's compiled code size
OS X release build executable size dropped from 672k to 511k
2012-07-17 12:47:01 -07:00
ridiculousfish
977a4477f6 Fix for process completion on Linux 2012-07-16 12:19:41 -07:00
ridiculousfish
33c6410809 Implemented process expansion on OS X
Also fixed issue where process expansion would always fail for processes with spaces
Fixes https://github.com/fish-shell/fish-shell/issues/56
2012-07-16 12:06:02 -07:00
maxfl
7e321afd2a pacmatic and dmesg completions 2012-07-16 10:03:01 +08:00
ridiculousfish
548ea1e54a Added binding for accepting an autosuggestion
Fixes https://github.com/fish-shell/fish-shell/issues/226
2012-07-15 14:02:34 -07:00
ridiculousfish
4755c5f8c8 Deliver SIGHUP when we're exiting, even if stdin is not closed.
Fixes https://github.com/fish-shell/fish-shell/issues/138
2012-07-15 12:46:40 -07:00
ridiculousfish
ea1bfd715e Set of changes to improve Unicode support with respect to combining characters.
Should address https://github.com/fish-shell/fish-shell/issues/155
2012-07-15 10:45:18 -07:00
Kevin Ballard
b1281c3fb9 Update __fish_git_prompt.fish to handle git-svn better
Git-svn remotes can have a prefix for their remotes. If I set a prefix
of 'svn/' then my remote trunk branch is called svn/trunk. Update the
script to use the svn-remote.*.fetch key to figure out how the 'trunk'
branch is mapped into the remotes namespace and apply this to the
current branch. This assumes branches are mapped into the same
namespace, which is likely. It also doesn't work for tags, but neither
did the old code.
2012-07-13 21:46:57 -07:00
Alex Rosenberg
257e9b04fe Add auto-generated builtin_scripts.[cpp|h] to .gitignore 2012-07-13 21:40:11 -07:00
ridiculousfish
8643870822 Tweaked fish_prompt document in a way I hope clarifies it 2012-07-13 21:32:50 -07:00
Dario Bertini
6819696222 Added small note to the fish_prompt doc 2012-07-12 14:52:15 -07:00
ridiculousfish
193bbd4e00 Tweaked pwd note about symbolic links 2012-07-12 14:48:51 -07:00
Dario Bertini
1bf168348e Added doc for pwd 2012-07-12 14:45:37 -07:00
ridiculousfish
f8b4c1b389 First pass at making autosuggestions not trigger wrapping
Addresses https://github.com/fish-shell/fish-shell/issues/167
2012-07-12 12:51:47 -07:00
ridiculousfish
830fba64b1 Fix for https://github.com/fish-shell/fish-shell/issues/42
Remote completions in scp
2012-07-11 17:20:58 -07:00
ridiculousfish
1cd61952b0 Fix for https://github.com/fish-shell/fish-shell/issues/223
Use -rpath instead of -R
2012-07-11 17:18:49 -07:00
ridiculousfish
4ee1cc3b37 Fix for https://github.com/fish-shell/fish-shell/issues/168
Make ^ only act as a redirect at the beginning of a token
2012-07-10 20:30:54 -07:00
maxfl
11dd904b6d Tests for contains -i 2012-07-10 16:21:00 -07:00
maxfl
0c03b6ddc7 Allow 'contains' builtin to return index
Add an option -i/--index to the contains builtin to print the index
of first coincidence.
2012-07-10 16:21:00 -07:00
ridiculousfish
176a3913aa Fix for https://github.com/fish-shell/fish-shell/issues/106
Lets us configure and build on FreeBSD
2012-07-10 15:37:16 -07:00
ridiculousfish
6f0b00f983 Fix for https://github.com/fish-shell/fish-shell/issues/66
Make fish import .bash_history if regular history is not found
2012-07-09 22:54:08 -07:00
ridiculousfish
69ace201f8 Fix for https://github.com/fish-shell/fish-shell/issues/79
Release tarballs with the user docs already build, removing the doxygen dependency
2012-07-09 19:41:51 -07:00
ridiculousfish
a04f31c5c0 Fix for https://github.com/fish-shell/fish-shell/issues/218
make help smarter on OS X (don't show useless builtin man page)
2012-07-09 18:46:14 -07:00
ridiculousfish
1d9f47d1e5 https://github.com/fish-shell/fish-shell/issues/207
Improve error message for infinite loop detection
2012-07-09 15:18:22 -07:00
ridiculousfish
36a91fc6ff Fix for https://github.com/fish-shell/fish-shell/issues/28
Use pthread_sigmask instead of sigprocmask
2012-07-09 14:15:55 -07:00
ridiculousfish
cd3ed71137 Fixes Solaris kludge https://github.com/fish-shell/fish-shell/issues/76 2012-07-08 22:36:04 -07:00
ridiculousfish
73e56527bf Improve error message for $? 2012-07-08 18:51:52 -07:00
ridiculousfish
24059924b1 Fix for https://github.com/fish-shell/fish-shell/issues/50
Unescape characters before calling parser.error
2012-07-08 18:40:50 -07:00
ridiculousfish
bb100a2511 Turn on debugging symbols correctly for OS X build 2012-07-08 18:04:31 -07:00
ridiculousfish
0c8c32cd03 Fix for https://github.com/fish-shell/fish-shell/issues/105
Not sure why the escape character was being printed in the manpage completions script
2012-07-08 17:35:07 -07:00
ridiculousfish
a38d6e74f5 Renamed a target in the OS X build system 2012-07-08 16:51:39 -07:00
ridiculousfish
05d8dacb27 Simplified native OS X build system 2012-07-08 16:17:49 -07:00
ridiculousfish
d6a0859eab Updated doc dir path in fish.cpp 2012-07-08 15:42:47 -07:00
ridiculousfish
4912967eab Large set of changes related to making fish relocatable, and improving the build and install story.
- etc/config.fish and share/config.fish are now "universal" and no longer reference install paths or need to be touched by autotools. They've been removed from config.fish.in to config.fish.
- fish now attempts to determine __fish_datadir and __fish_sysconfdir relative to the path of the fish executable itself (typically by walking up one directory). This means that you can copy the directory hierarchy around and things will still work. The compiled-in paths are used as a backup.
- The fish Xcode project now can build fish natively, without needing autotools.
- Version bumped to 2.0
2012-07-08 15:20:39 -07:00
maxfl
76e1cda495 Set single-line default prompt
Fish now doesn't join the fish_prompt output. This breaks the default
fish_prompt. Make default fish_prompt single-line. Fixes #203.

Add -l flag to 'read' documentation. Remove ambiguous '-x' description.
Fixes #157.
2012-07-07 23:34:16 -07:00
ridiculousfish
c1a23bf450 Fix for https://github.com/fish-shell/fish-shell/issues/199
Don't hard-fail on setting the PATH or CDPATH just because it contains an invalid entry
2012-07-07 23:04:02 -07:00
maxfl
b25b5bf5f6 restore tabs instead of spaces 2012-07-08 10:55:48 +08:00
maxfl
079f17761c Fix case when first index is command substitution 2012-07-08 09:45:34 +08:00
maxfl
e1b8c425da Fix case when second limit is a variable:
echo $PATH[1..$n]
2012-07-08 09:39:39 +08:00
maxfl
5f05756e65 Add variable expand ranges
echo $PATH[-1..1] #now works

Add tests for ranges
2012-07-08 09:19:11 +08:00
maxfl
c0e996acf8 Implemented index ranges for command substitution
Now the following code works:
> echo (seq 10)[-1..1]
With output:
10
9
8
7
6
5
4
3
2
1
2012-07-07 22:01:28 +08:00
maxfl
41ec58a524 misc 2012-07-07 11:04:29 +08:00
maxfl
0a5e7be129 Add index ranges
Builtin 'set' now can set variable index ranges:
  set test[1..3] a b c #works
  set test[-1..-3] a b c #works if variable have enough elements
  set test[2..-2]  a b c #works
  set test[1..3 -1..-2] a b c b b #works

Expand now can parse index ranges. But not handle for now.

TODO:
  * Add variable substitution index ranges: echo $PATH[-1..1]
  * Add command substitution index range: echo (seq 10)[-1..-4]
  * Add process substitution indexes and ranges: echo %vim[-1]
2012-07-07 10:57:28 +08:00
maxfl
b23d65b014 Set single-line default prompt
Fish now doesn't join the fish_prompt output. This breaks the default
fish_prompt. Make default fish_prompt single-line. Fixes #203.

Add -l flag to 'read' documentation. Remove ambiguous '-x' description.
Fixes #157.
2012-07-07 10:17:24 +08:00
ridiculousfish
60ef7903e2 Tweaked __fish_print_help to not spew errors 2012-07-06 16:31:06 -07:00
ridiculousfish
ee8fd21d28 Fix for https://github.com/fish-shell/fish-shell/issues/209
Don't hang if stdin is closed and we have no bindings
2012-07-06 16:25:59 -07:00
maxfl
232ed91ec7 Fix read default prompt. It's now single line. 2012-07-06 15:31:45 -07:00
maxfl
7fccad156e Fix fish_prompt event
I've found that this modification fixes fish_prompt event
Fixes #164
2012-07-06 15:31:45 -07:00
ridiculousfish
11e56456a0 Fix for wrong sense for determining when an autoloaded function has changed
Addresses some of the complaints in https://github.com/fish-shell/fish-shell/pull/201
2012-07-06 15:30:41 -07:00
Emily Eisenberg
d07e78c59a Make prompt_pwd make a lot more sense
Remove the case statements, which were handled by the sed blocks anyway
Move around the '/' character in the regex, so only one regex is needed
Fix a bug where '/' is output as '//'
2012-07-06 14:46:50 -07:00
Sean DuBois
c45479a6e5 Created the man page for echo and test 2012-07-06 14:41:44 -07:00
ridiculousfish
345a528625 Untangle unescaping responsibilities in highlight.cpp. Fix cd autosuggestions to properly handle quotes. Factor out some of the quote unescaping behavior from reader.cpp to parse_util.cpp.
Add some autosuggestion tests
2012-07-06 14:34:53 -07:00
maxfl
01d8490255 Return the previous logic for '\\'.
The following expression now works:
```sh
switch '\\'
  case '\\'
  echo 1
end
```

Due to ambiguity, the following expression also works:
```sh
switch '\a'
  case '\\a'
  echo 1
end
```

By the way, the following expression now doesn't work, which was not the
case before, because of wrong escaping:
```sh
switch 'nn'
  case '\n'
  echo 1
end
```
2012-07-05 14:17:25 -07:00
maxfl
ea4b37d5c5 Fixed case behaviour
* case no properly handles -h and --help flags, i.e. treats it as
  pattern
* fixed case escaping:
The following expressions now work correctly:
switch '*'
  echo '*'
  echo Match any string
end
switch '*'
  echo '\*'
  echo Match asterix
end
switch '\\'
  echo '\\\\'
  echo Match slash
end

The same for '?' sign
2012-07-05 14:17:25 -07:00
Siteshwar Vashisht
a1319cb8aa Fixed crash caused by pressing pageup button when no match (for typed command) in history is found 2012-07-05 16:06:39 +05:30
ridiculousfish
35c49d62d7 Fix a class/struct disparity 2012-07-01 16:11:14 -07:00
ridiculousfish
0576a11a6f Added missing break in case R_SUPPRESS_AUTOSUGGESTION 2012-07-01 15:40:06 -07:00
Ian Munsie
c8f86d94c9 Add command to temporarily suppress the autosuggestion feature
Autosuggestion will be automatically re-enabled next time a character is
inserted. An alternative implementation would require another command to
explicitly re-enable it.

Signed-off-by: Ian Munsie <darkstarsword@gmail.com>
2012-07-01 15:37:10 -07:00
Ian Munsie
2b24eab26a Fix off by two in move_word left
This can be demonstrated with something like:

echo howdy hi<control-w>
echo howdy I<alt-b>

Previousely this would delete/move all the way to the start of 'howdy',
rather than just the word 'hi'/'I'.

It seems that the code to ignore the character under the cursor was
redundant, as all the cases I've tried with it removed seem to do the
right thing.

Signed-off-by: Ian Munsie <darkstarsword@gmail.com>
2012-07-01 15:37:10 -07:00
ridiculousfish
7bbc7a61ce Clarify the function name deferral in functions_def
Prohibit making a function with an empty name
2012-07-01 15:33:50 -07:00
maxfl
fe26284376 Doc is updated
btw. funced completion is updated
2012-07-01 14:20:43 -07:00
maxfl
ab62fe6496 Update funced
* Editor mode is no the default
* Use -i or --interactive or -e fish to edit function in interactive
  mode
* tmpname is now created with random number added and check that file
  do not already exist
* check $TMPDIR existence and put /tmp if it does not exist
* There is an undocumented feature to use functions, started with dash.
  Introduce necessary changes to funced, functions, def_function()
  in order to make it work properly.
* Delete editor guessing. Use $EDITOR variable or -e key
2012-07-01 14:20:43 -07:00
ridiculousfish
bc9bae0f7f Update make_tarball.sh to respect new branch name 2012-07-01 14:19:39 -07:00
maxfl
e5939d1a18 Disable default fish_pager_color_secondary
since it should be different, depending on terminal background
2012-06-29 18:53:22 -07:00
maxfl
5fadb7f200 fix logic 2012-06-29 18:53:22 -07:00
maxfl
a02aa7a316 Step coloring for fish_pager introduces new variable
fish_pager_color_secondary to set background of every second completion
line. It simplifies finding the options corresponding to given
description. Default color is 151515.
2012-06-29 18:53:22 -07:00
ridiculousfish
3ab26a5d40 Updated funced documentation to reflect new behavior 2012-06-29 18:41:37 -07:00
ridiculousfish
a8bae31939 Change funced script to default to using $EDITOR if set, and to allow -e to specify a particular editor (with fish meaning the builtin editor) 2012-06-29 18:35:26 -07:00
maxfl
faea588fb8 Support editing functions starting with dot 2012-06-29 16:42:34 -07:00
maxfl
792e246262 Add emacs to 'funced -e'
The order is also changed.
2012-06-29 16:42:34 -07:00
maxfl
85f19f9b8c Add -e option to funced
New option -e or --editor allows to edit function inside external
editor, rather than in reader.
2012-06-29 16:42:34 -07:00
ridiculousfish
40e4f49dbe Disable process expansion in autosuggestions
Addresses https://github.com/fish-shell/fish-shell/issues/39
2012-06-29 16:40:54 -07:00
Siteshwar Vashisht
05c721bebb Some improvements to validate commands suggested from history 2012-06-29 00:24:37 +05:30
maxfl
e995cc9329 fix #177 (complete 'cd' only with paths) 2012-06-26 19:17:32 -07:00
ridiculousfish
9457c115be Merge pull request #181 from kballard/fish_git_switch
Remove __fish_git_prompt's switch bug workaround
2012-06-26 13:00:31 -07:00
Kevin Ballard
1eddc79a90 Remove __fish_git_prompt's switch bug workaround
With the switch bug fixed, __fish_git_prompt can be very slightly
simplified by not recording the exit status of every case in the
describe style switch individually.
2012-06-25 15:19:47 -07:00
Siteshwar Vashisht
ccfc909eb2 Fixed crash caused by pressing pageup button 2012-06-25 03:02:37 +05:30
Kevin Ballard
1a93cbba1e Bring prompt_pwd under Darwin to parity with non-Darwin
The echo command to print the last path segment got a couplel of fixes,
but these fixes were only applied to the non-Darwin version. Copy these
fixes over to the Darwin version. Notably, this makes `/` stop
displaying as `//`.
2012-06-24 14:04:43 -07:00
Kevin Ballard
529d410bec Fix prompt_cwd on darwin systems when $PWD is "/private"
When $PWD is "/private", the prompt was printing "rivate". Skip the
"/private" stripping if there's nothing after it.

Prevent "/private" from being stripped anywhere but the beginning of the
PWD.

Fixes #173
2012-06-24 14:04:43 -07:00
Kevin Ballard
4d1c0eaa52 Fix var set in __fish_config_interactive.fish
__fish_config_interactive.fish uses the presence of __fish_init_1_50_0
to decide whether it should perform a one-time initialization of
universal variables. Unfortunately, it sets the variable
__fish_init_1_23_0. Fix this to set __fish_init_1_50_0 instead.
2012-06-24 13:57:15 -07:00
Kevin Ballard
adfd3c1098 Don't blow away $status in switch statements
Tweak the switch and case builtins to not blow away $status
inappropriately. Fixes issue #161.
2012-06-24 13:43:44 -07:00
Kevin Ballard
f7d0c4b065 Add a test case for switch error code (issue #161) 2012-06-24 13:43:44 -07:00
Siteshwar Vashisht
5fb32f1e2d Fixed declaration of wrealpath() function on FreeBSD 2012-06-23 10:59:53 +05:30
ridiculousfish
f69489a4fc Mostly fix https://github.com/fish-shell/fish-shell/issues/72 2012-06-21 16:58:26 -07:00
ridiculousfish
d34ce26c4e Merge pull request #169 from kballard/git_prompt_docs
Tweak documentation for __fish_git_prompt
2012-06-21 16:34:12 -07:00
Kevin Ballard
3f7fe94009 Tweak documentation for __fish_git_prompt
Add mention of the __fish_git_prompt_color variable.
2012-06-21 11:14:01 -07:00
Kevin Ballard
ae593decfc Replace __fish_git_branch_prompt.fish with __fish_git_prompt.fish
__fish_git_prompt.fish is a complete port of the __git_ps1 function from
git-completion.bash, with the relevant configuration variables changed
and some extra configuration added (namely, control over individual
colors and the status indicator characters).
2012-06-21 11:03:15 -07:00
Emil Eriksson
eea62125a1 Fixes title update in tmux and screen
* Seems that writestr( L"\x1b];" ); doesn't work in tmux and
	  screen. As discussed in fish-shell/fish-shell#47 the 2 was
	  removed. This commit adds the zero (L"\x1b]0;").
	* Tested in screen,tmux,iTerm and xterm.
2012-06-21 10:30:12 -07:00
Emil Eriksson
96f36a63dc Enable window title update when TERM is screen-X
* Uses the same logic as when TERM is
	  xterm-X to enable window-title updates when
	  running in screen.
2012-06-21 10:30:12 -07:00
ridiculousfish
19e183f02f Squashed commit of the following:
commit 5b7659ec3d5e67b8dad8d3543d87a0169dc9a9e9
Merge: 57f3df3 22a4cd6
Author: ridiculousfish <corydoras@ridiculousfish.com>
Date:   Thu Jun 21 10:15:41 2012 -0700

    Merge branch 'master' of https://github.com/maxfl/fish-shell into maxfl-master-base

commit 22a4cd686f
Author: maxfl <gmaxfl@gmail.com>
Date:   Tue Jun 19 15:51:43 2012 +0400

    set now expands the variable size, if index is outside it

commit 9b0ffa8315
Author: maxfl <gmaxfl@gmail.com>
Date:   Mon Jun 18 21:30:44 2012 +0400

    fixes #78

commit 78387fb391
Merge: c0e6096 93dc7d4
Author: maxfl <gmaxfl@gmail.com>
Date:   Mon Jun 18 21:27:47 2012 +0400

    Merge remote-tracking branch 'fishfish/master'

commit c0e60963c1
Merge: 32a98e7 1bead8a
Author: maxfl <gmaxfl@gmail.com>
Date:   Mon Jun 18 10:29:42 2012 +0400

    Merge remote-tracking branch 'fishfish/master'

commit 32a98e799e
Merge: 6e71021 f2b5292
Author: maxfl <gmaxfl@gmail.com>
Date:   Sat Jun 16 18:42:07 2012 +0400

    Merge remote-tracking branch 'fishfish/master'

commit 6e710211bc
Author: maxfl <gmaxfl@gmail.com>
Date:   Thu Jun 14 11:01:13 2012 +0400

    revert fish_pager

commit 731a29f35b
Author: maxfl <gmaxfl@gmail.com>
Date:   Thu Jun 14 10:57:41 2012 +0400

    revert fish_pager.cpp

commit 72c1bfc7bf
Merge: ea74ffa 9b781c4
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 17:54:11 2012 +0400

    Merge branch 'master' into maxfl_completions

commit ea74ffa086
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 17:35:20 2012 +0400

    __fish_complete_command now can understand '--arg=option' tokens
    latexmk completion is updated

commit 45b667826f
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 16:46:47 2012 +0400

    . completion

commit 1c9f8ffc9e
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 16:46:13 2012 +0400

    a lot of new completions

commit 8224d9f984
Author: Maxim Gonchar <gonchar@myhost.localdomain>
Date:   Tue Jun 12 20:19:31 2012 +0400

    A lot of new completions.
    Some small updates and fixes of old functions and completions.

commit 234ed8f5da
Author: Maxim Gonchar <gonchar@myhost.localdomain>
Date:   Tue Jun 12 20:03:44 2012 +0400

    step-coloring initial
    set_color correction
2012-06-21 10:24:49 -07:00
Siteshwar Vashisht
57f3df3cab Fix for crash while editing multiple lines requested in issue #143 2012-06-21 21:05:14 +05:30
David Adam (zanchey)
08e78e63cf docs: fix percentage sign escape character
(Patch taken from Debian packaging.)
2012-06-18 14:01:22 -07:00
ridiculousfish
9228dffe5e Don't generate completions if we already have bespoke completions in the data directory
Fixes https://github.com/fish-shell/fish-shell/issues/148
Also fix some Python3 issues
2012-06-18 13:59:34 -07:00
Siteshwar Vashisht
93dc7d4cc1 Add support for querying variables with scope options as requested in issue #132 2012-06-18 22:52:33 +05:30
ridiculousfish
1bead8adf7 Fix to create_manpage_completions.py to flush after every line (so you see more progress) and to put the cursor at the beginning (so it doesn't jump around) 2012-06-17 15:19:55 -07:00
David Adam (zanchey)
6681f3bfec only touch user_doc if doxygen installed
If doxygen isn't installed, an empty file called user_doc will be created.
If doxygen is later installed, the documentation will not generate correctly.
2012-06-17 15:04:20 -07:00
David Adam (zanchey)
71f8960ef1 make clean should remove all generated documentation 2012-06-17 15:04:20 -07:00
Evan Jones
01780f19b1 Fix other usages of \n in sed replacements. 2012-06-17 15:01:04 -07:00
Evan Jones
1fa0c4d4d3 alias: Support seds that don't support \n in replacements.
This makes the alias command work on Mac OS X.
2012-06-17 15:01:04 -07:00
ridiculousfish
eebe126842 Fix for a busted format string 2012-06-17 14:49:45 -07:00
ridiculousfish
ebfa285122 Teach __fish_print_help.fish about the new man path 2012-06-17 14:46:24 -07:00
ridiculousfish
27212719dc Removed an errant printf 2012-06-17 13:20:31 -07:00
Siteshwar Vashisht
17567028da Fixed a bug in wsetlocale() 2012-06-17 11:25:21 +05:30
ridiculousfish
34fd8e0e00 Tweak fork guards to be more forgiving
Fixes https://github.com/fish-shell/fish-shell/issues/101
2012-06-16 21:25:33 -07:00
ridiculousfish
6cf42075fc Fix to check for case insensitive filesystems in is_potential_path
Addresses https://github.com/fish-shell/fish-shell/issues/119
2012-06-16 14:08:58 -07:00
ridiculousfish
afd8d2f9ba Fix for https://github.com/fish-shell/fish-shell/issues/135
Don't use std::map::insert when we need to overwrite values
2012-06-16 13:05:58 -07:00
ridiculousfish
1d54bff385 Disble futimes() calls in hopes of fixing https://github.com/fish-shell/fish-shell/issues/122
This should keep sudo from thinking that the tty has changed as part of its tty_tickets feature.
2012-06-16 12:30:20 -07:00
ridiculousfish
6dd0013a5d Fix for extra space in some completions
Addresses https://github.com/fish-shell/fish-shell/issues/60
2012-06-16 10:30:05 -07:00
ridiculousfish
f2b5292bcb Squashed commit of the following:
commit 33358874f1c275d8b08186e29f24a7889d2b5224
Author: maxfl <gmaxfl@gmail.com>
Date:   Thu Jun 14 11:01:13 2012 +0400

    revert fish_pager

commit cee1bc8a66ec3adc9573b76e1aca3131cd32db83
Author: maxfl <gmaxfl@gmail.com>
Date:   Thu Jun 14 10:57:41 2012 +0400

    revert fish_pager.cpp

commit 27f3bd39dd9903009503d20a59a9e2ba84add07a
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 17:35:20 2012 +0400

    __fish_complete_command now can understand '--arg=option' tokens
    latexmk completion is updated

commit 97b53a4b53de9389675783f3e90f58215d936356
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 16:46:47 2012 +0400

    . completion

commit d5b63b9963b0a02a71f564e7392171c5eab005cd
Author: maxfl <gmaxfl@gmail.com>
Date:   Wed Jun 13 16:46:13 2012 +0400

    a lot of new completions

commit ceab87d99425124aa010c64ed062e27202b850d2
Author: Maxim Gonchar <gonchar@myhost.localdomain>
Date:   Tue Jun 12 20:19:31 2012 +0400

    A lot of new completions.
    Some small updates and fixes of old functions and completions.

commit 950aecd570b51e1b9dc444cc651b282a220e8d94
Author: Maxim Gonchar <gonchar@myhost.localdomain>
Date:   Tue Jun 12 20:03:44 2012 +0400

    step-coloring initial
    set_color correction
2012-06-15 17:30:33 -07:00
Gour-Gadadhara Dasa
3a94f6e8b3 initial version of Bazaar completion (created automatically) 2012-06-15 17:18:15 -07:00
Peter Feigl
f2846a0b78 correcting path of man-pages to ./man/man1/ instead of ./man/
Change the path where man-pages are installed to
/usr/share/fish/man/man1 instead of /usr/share/fish/man, so that tools
like mandb can process it.
2012-06-15 16:31:35 -07:00
Tim Gray
dbde7033d8 Added completions for brew (Homebrew)
An OS X package manager.
http://mxcl.github.com/homebrew/
2012-06-15 16:29:26 -07:00
ridiculousfish
18f04adccb Support for importing fish 1.x's history and format, and also bash 2012-06-15 16:24:05 -07:00
ridiculousfish
1ed65b6bd7 Fixed token search (note: this didn't work properly even in the original fish!)
Fixes https://github.com/fish-shell/fish-shell/issues/61
2012-06-15 16:24:05 -07:00
Siteshwar Vashisht
9b781c4c06 Modified alias.fish to show help message when executed with 0 arguments 2012-06-13 00:29:05 +05:30
Siteshwar Vashisht
25f9105a97 Made history --help show history man page and history is now saved only once while deleting items 2012-06-12 14:20:07 +05:30
Siteshwar Vashisht
602109bd8d Some improvements in bash configuration importer script 2012-06-12 11:08:30 +05:30
ridiculousfish
631d27f7a8 Merge pull request #104 from Teggy/master
Please consider to pull: formatting glitch in doc_src/history.txt makes Doxygen stumble
2012-06-11 15:48:00 -07:00
Torsten Grust
aad27a7a68 Fixed closing <pre> tag
- Was an opening tag, should have been a closing tag
- Confused Doxygen 1.8.1.1 on my machine (OS X 10.7), resulting in the fish man pages not being installed at all
2012-06-11 13:46:47 +02:00
ridiculousfish
4ac01154d9 SIGXCPY should be SIGXCPU
Fixes https://github.com/fish-shell/fish-shell/issues/97
2012-06-10 03:36:02 -07:00
ridiculousfish
4e2c7c57d7 Add text to INSTALL describing how to go back to the old shell.
This was requested in https://github.com/ridiculousfish/fishfish/pull/92
2012-06-10 01:35:30 -07:00
Robin Deits
6e65cfcc9a fish_title now sets both tab and window titles in iTerm2 2012-06-10 00:50:00 -07:00
Carl Johan Crafoord
96a4b7eaa7 Check for libiconv_open if we can't find iconv_open 2012-06-10 00:33:01 -07:00
ridiculousfish
64afada7f0 Switched from using 'type' to 'functions --query' since it's a lot cheaper 2012-06-10 00:21:11 -07:00
adisbladis
9f563f4873 Introduced fish_user_keybindings 2012-06-10 00:21:11 -07:00
Siteshwar Vashisht
ca61d0ee8b Fixed crash in history builtin for inputs like : history --search -prefix "echo" 2012-06-10 01:08:19 +05:30
Siteshwar Vashisht
e96dabadf1 Add Rekonq in list of browsers to display help 2012-06-08 21:11:26 +05:30
Siteshwar Vashisht
b6601338c2 Made C-d delete characters in multiple lines. 2012-06-07 21:18:02 +05:30
Siteshwar Vashisht
8167e1e07e Add new line after printing job information with jobs builtin. 2012-06-07 21:07:34 +05:30
Siteshwar Vashisht
23ce927301 Fixed a bug in manpage generator. 2012-06-07 20:48:54 +05:30
Siteshwar Vashisht
c7941fc7b0 Use manpath instead of man --path to find man page paths. 2012-06-07 00:00:43 +05:30
Siteshwar Vashisht
1078ad9ae9 Fixed following bugs in history function:
1. history function without any argument now correctly shows user's command history.
2. history --save now saves user's command history.
2012-06-06 20:54:27 +05:30
adisbladis
c0085cbc61 Python3 fixes in import_bash_settings.py 2012-06-05 20:40:51 -07:00
Adam
a49d245b92 Python3 fixes for webconfig.py 2012-06-05 20:40:51 -07:00
Adam
0ce6829e4c Python3 fixes in make_completions.py 2012-06-05 20:40:51 -07:00
Adam
4e3acdcbdc Unicode error fix in manpage completion with python3 2012-06-05 15:26:11 -07:00
Adam
85f808130d Manpage generation now works with python3 2012-06-05 15:26:11 -07:00
ridiculousfish
b187538339 Bump OS X installer package version 2012-06-05 02:06:44 -07:00
ridiculousfish
93f6aabe12 Fix to stop identifying SnowLeopard's terminal as term256 2012-06-05 02:06:33 -07:00
ridiculousfish
10aa107380 Updated relnotes 2012-06-05 01:22:25 -07:00
ridiculousfish
53cba2a2e6 Improved webconfig.py's handling of combined term256 and classic colors 2012-06-05 01:19:59 -07:00
ridiculousfish
d871095d0b Updated "last run version" to __fish_init_1_50_0. Updated colors for non term-256 compatibility 2012-06-05 01:01:30 -07:00
ridiculousfish
9bf8a5e877 Updated release notes for new history syntax 2012-06-05 00:42:45 -07:00
ridiculousfish
3836bfe5a1 Added history completion file
Updated history function to assume --search as the default behavior
2012-06-05 00:40:42 -07:00
ridiculousfish
7698553c3a Made a bare history call end with a newline 2012-06-04 23:59:04 -07:00
ridiculousfish
be1d216b34 Relnoted history builtin
Tweaked validation regex to use extended regexs
2012-06-04 23:54:43 -07:00
ridiculousfish
85cbb943b5 Tweaks to the history function 2012-06-04 23:40:08 -07:00
Siteshwar Vashisht
ec34f2527a Adding history builtin 2012-06-05 09:54:42 +05:30
ridiculousfish
b877181e17 Fix for what I believe to be a bug in fish trunk where you can't always successfully control-C out of some while loops 2012-06-04 15:10:35 -07:00
ridiculousfish
69446be1ee Signal handling cleanup and improved safety
Fixes issue where you couldn't control-C out of a loop (https://github.com/ridiculousfish/fishfish/issues/13)
Also stops doing memory allocation in the signal handler (oops) https://github.com/ridiculousfish/fishfish/issues/27
2012-06-04 14:20:01 -07:00
ridiculousfish
cc90f9cf80 path_make_canonical mishandles empty string.
Fixes https://github.com/ridiculousfish/fishfish/issues/26
2012-06-04 12:00:59 -07:00
ridiculousfish
457e6a5f46 Updated some relnotes for beta r2 2012-06-03 17:58:25 -07:00
ridiculousfish
e7db18bae2 Added Debian description-pak file 2012-06-02 18:07:11 -07:00
ridiculousfish
f8e3e853aa Fix to disable VDSUSP, which allows control-Y to serve as yank on OS X 2012-06-02 15:43:18 -07:00
ridiculousfish
b7ba252965 Restore implicit cd for paths starting with ., .., or ~ 2012-06-02 14:04:25 -07:00
ridiculousfish
ae12e1b537 insert_tabs called wcstring::append with arguments in the wrong order
Should fix https://github.com/ridiculousfish/fishfish/issues/18
2012-06-01 14:38:41 -07:00
ridiculousfish
9255f625fa Disable internalized scripts 2012-06-01 14:00:04 -07:00
adisbladis
377d93d1cf Missing -s to which fixed 2012-05-30 21:08:44 +02:00
adisbladis
19d14c7c3a Python 3 compatibility fix in make_completions.py 2012-05-30 11:52:49 +02:00
adisbladis
6e3a823b7b Python 3 compatibility fix in internalize_scripts.py 2012-05-30 11:42:32 +02:00
ridiculousfish
51f9ff5389 Updated make_tarball.sh to stop dumping files in the extract directory 2012-05-30 01:06:25 -07:00
ridiculousfish
4986e6e3f9 Fix to set up 10.6 SDK correctly when building on 10.7 2012-05-30 00:27:50 -07:00
Peter Ammon
9d8ae184c9 Fix for annoying messages when launching on SnowLeopard
Fix for missing .o file in Makefile.in
2012-05-30 00:22:45 -07:00
ridiculousfish
4afdcf56fc Tweak a few default colors
Fix the make_pkg script to actually build an installable package that doesn't immediately barf
2012-05-29 21:14:19 -07:00
ridiculousfish
0fe43eb880 Fix to (really) no longer require Doxygen to build fish 2012-05-29 20:50:27 -07:00
ridiculousfish
4edfd6d9d6 Update set_color documentation 2012-05-25 02:14:26 -07:00
ridiculousfish
8351ec0afd Document some of the new commands 2012-05-25 02:07:21 -07:00
ridiculousfish
92ce84c26a More tweaks to Debian build script 2012-05-25 00:48:39 -07:00
ridiculousfish
9d31e52b2a Updated Debian package build script 2012-05-24 23:58:16 -07:00
ridiculousfish
dcd7d6769d Updated some build scripts 2012-05-24 23:56:07 -07:00
ridiculousfish
87c0e0e971 Tweaked make_deb script 2012-05-22 00:09:39 -07:00
ridiculousfish
6f9a523151 Some tweaks to build tools
Started make_deb.sh for Debian package
2012-05-22 00:05:41 -07:00
ridiculousfish
673faf7152 Fixed builtin_test to properly handle "just a strings" in combining expressions, like 'test foo -a bar'. This was causing error messages in the help function.
Fixed help function to know about OS X and use the open command to open web pages.
2012-05-20 12:58:03 -07:00
ridiculousfish
18ace555b0 Added release notes for beta 1 2012-05-19 17:04:45 -07:00
ridiculousfish
d09c9fba02 Added a -s option to echo to mean "don't output spaces"
Replaced default prompt to stop calling printf. I opened a bug to replace the default prompt entirely with one that's cheaper.
2012-05-19 16:59:56 -07:00
ridiculousfish
f1d22b6300 Got function.h and function.cpp off of shared_ptr (hooray) 2012-05-18 14:00:36 -07:00
ridiculousfish
da6295c428 More work towards getting function.h off of shared_ptr 2012-05-17 19:46:08 -07:00
ridiculousfish
86645b32e1 Work towards getting function.h off of shared_ptr 2012-05-17 19:38:08 -07:00
ridiculousfish
977c585f8b Made the OS X installer package flat 2012-05-17 19:37:26 -07:00
ridiculousfish
4c1ddab560 Tweaked Makefile.in to show off a few of our new features 2012-05-17 19:37:03 -07:00
ridiculousfish
f5442bdd4a Fixed cd autosuggestion for absolute paths
Removed some unnecessary path cleanup that is_potential_path now handles
2012-05-13 20:49:14 -07:00
ridiculousfish
129525af21 Fix for https://github.com/ridiculousfish/fishfish/issues/3
cd's special autosuggestion was broken, now fixed. Also, there's some tests for it now.
2012-05-13 20:19:02 -07:00
ridiculousfish
c15975113a Fix for https://github.com/ridiculousfish/fishfish/issues/2 2012-05-11 18:59:38 -07:00
ridiculousfish
2d3d6e1c17 Added PackageMaker file
Updated make_pkg.sh to use it
2012-05-11 17:26:08 -07:00
ridiculousfish
b0f4ff2879 Added build_tools folder so we can automate release builds 2012-05-10 02:11:28 -07:00
ridiculousfish
070b10689c Added .gitattributes to ignore new build_tools directory from archival 2012-05-10 02:10:39 -07:00
ridiculousfish
39863ce4d7 Fix for longstanding bug where set -e would fail to erase elements from an array.
This was introduced in 7b3377e78c
2012-05-10 01:04:18 -07:00
ridiculousfish
7cae1ae415 Make key_reader build and work 2012-05-09 03:30:09 -07:00
ridiculousfish
eca2100312 Cleanup SHLVL variable 2012-05-09 03:23:31 -07:00
ridiculousfish
175249b455 Adopt wcstring in env_set 2012-05-09 03:06:10 -07:00
ridiculousfish
294fbc8309 Replaced some calls to unescape with unescape_string 2012-05-09 02:55:36 -07:00
ridiculousfish
9bcc7df96f Lots of modernization changed
Removed wcsdupcat
2012-05-09 02:33:42 -07:00
ridiculousfish
4bd63020ca Fix to add a little explanatory text to colors in the web config interface 2012-05-08 17:10:38 -07:00
ridiculousfish
4885842ae8 Fix to do really nice syntax highlighting of cd command where it colors paths that cannot match any directory with error color 2012-05-07 17:52:02 -07:00
ridiculousfish
4df6b599b8 Eliminate the silly autosuggest_parsed_command_t class; make it just a function 2012-05-07 17:43:05 -07:00
ridiculousfish
0c79bb6e7c Factor is_potential_path to properly handle CDPATH
This will let us color cd commands better
2012-05-07 17:31:24 -07:00
ridiculousfish
1a264ab7c2 Made tests compile again
Renamed autosuggest_handle_special to autosuggest_special_validate_from_history
Began work to factor autosuggest_special_validate_from_history together with autosuggest_suggest_special
2012-05-07 12:55:13 -07:00
ridiculousfish
99b51ce6ea Fix to better support CDPATH 2012-05-06 14:53:19 -07:00
ridiculousfish
e0baab2722 Another effort to make the cd completion work without running command substitutions off of the main thread 2012-05-06 13:51:11 -07:00
ridiculousfish
71a8d39372 Fix to restore completions that use command substitution (like cd)
Fix to adopt the same escaping code for both completions and autosuggestions
2012-05-06 13:36:51 -07:00
ridiculousfish
90826e4031 Oops, had the wrong sense for when to call proc_push_interactive 2012-05-05 14:39:08 -07:00
ridiculousfish
0e4f2cca01 Fix to stop setting a default CDPATH 2012-05-05 14:34:59 -07:00
ridiculousfish
ac3dce38f0 Better fix to make cd completions work again 2012-05-05 14:33:24 -07:00
ridiculousfish
3be07cc645 Fix to start re-respecting CDPATH 2012-05-05 14:30:20 -07:00
ridiculousfish
07f5319472 Fix for failing to properly complete cd command 2012-05-05 14:21:21 -07:00
ridiculousfish
47019e315a Some work towards refactoring how completions are inserted to support escaping in autosuggestions 2012-05-05 13:34:09 -07:00
ridiculousfish
fe7fa46d57 Make dirh, nextd, prevd work on OS X 2012-05-04 18:53:38 -07:00
ridiculousfish
007c5bc9f0 Workaround difference between BSD and GNU seq in dirh
dirh still doesn't make any sense
2012-05-04 18:37:24 -07:00
ridiculousfish
8c423b56df Define a virtual destructor for lru.h 2012-05-04 18:37:12 -07:00
ridiculousfish
a868abb55a Minor cleanup of proc.cpp 2012-04-25 13:38:40 -07:00
ridiculousfish
ecab34c787 Make gettext function use echo instead of printf to save a fork 2012-04-25 13:37:41 -07:00
ridiculousfish
307ea6dce2 Removed extra newline from Goodbye output 2012-04-25 13:37:01 -07:00
ridiculousfish
d456b4f68e Removed useless deroff.py import from bash settings 2012-04-25 13:36:21 -07:00
ridiculousfish
17e815348b Fix to drain command output from quit commands before returning from job_continue
This should fix the bug where output from commands and builtins gets incorrectly interleaved.
I think this is a very long-standing bug that predates my work on the shell
2012-04-25 13:26:56 -07:00
ridiculousfish
953ab4b3cf Clean up __fish_config_interactive a little bit 2012-04-24 11:12:04 -07:00
ridiculousfish
9204780c1b Fix for a missing lock in complete_remove 2012-04-24 11:01:04 -07:00
ridiculousfish
fb2ed355ec Improve fork reporting
Save a couple of forks during init
2012-04-24 10:10:43 -07:00
ridiculousfish
675106cfa5 Include algorithm header so we can build on Linux 2012-04-23 19:29:44 -07:00
ridiculousfish
3aeadd9fb7 Fix for a deadlock when env_get_string ends up calling env_get_string 2012-04-23 11:08:29 -07:00
ridiculousfish
0e3eb38f11 Improved fork reporting
Made autosuggestion work properly for tilde expansion
2012-04-21 20:08:44 -07:00
Siteshwar Vashisht
dc23af6b32 Fixed setting PATH variable in import_bash_settings.py 2012-04-22 00:18:40 +05:30
ridiculousfish
b1bfa71338 Merge branch 'master' into CPlusPlus
Conflicts:
	builtin_commandline.cpp
	util.c
2012-04-18 13:41:39 -07:00
ridiculousfish
71bff26607 Merge remote-tracking branch 'upstream/master' 2012-04-18 13:21:03 -07:00
ridiculousfish
3c190374b4 Wrote tests for history merging, then made them pass. 2012-04-16 20:26:50 -07:00
ridiculousfish
d8428463d8 Fix to better handle merging histories between separate sessions 2012-04-15 22:49:27 -07:00
ridiculousfish
725982cc5b Fix to try to remove Python 2.7 dependency 2012-04-15 19:45:44 -07:00
ridiculousfish
f977dfcfe7 Deroffer optimizations 2012-04-15 19:22:30 -07:00
ridiculousfish
15079fa3bd Some more deroff optimizations 2012-04-15 04:41:20 -07:00
ridiculousfish
79a92120ef Speed improvements to deroffer 2012-04-15 01:15:10 -07:00
ridiculousfish
a34565ca0f Make screen.cpp properly compute the length of term256 escape codes 2012-04-13 14:40:16 -07:00
ridiculousfish
49ece586d5 Added a fish_update_completions function to run the manpage completion file
Added some pretty progress reporting to that script
Added some comments to deroff.py
2012-04-11 19:05:43 -07:00
ridiculousfish
2ec0778d78 Make create_manpage_completions output to ~/.config/fish/completions by default, and also discover man pages from reading the manpath 2012-04-11 18:26:26 -07:00
ridiculousfish
cccd1cefbe Make the web config page have a title and pass W3C validation 2012-04-11 18:26:10 -07:00
ridiculousfish
8f145fa7fa Fix for complete.cpp to print out completions in-order 2012-04-11 18:25:37 -07:00
ridiculousfish
ceb32f63e7 Deroffing completion work 2012-04-09 20:17:54 -07:00
ridiculousfish
576c12b184 Deroffer work 2012-04-09 20:17:54 -07:00
ridiculousfish
e2c3ca9950 Move completions from linked list to std::set 2012-04-09 20:17:06 -07:00
ridiculousfish
8585e0e9b8 Various improvements on completion tool 2012-04-04 12:43:12 -07:00
ridiculousfish
7394374a15 Work on improving the output of the manpage completion script 2012-04-03 18:38:25 -07:00
ridiculousfish
37defa739b Fix for an extra line at the end of the variable listing
Once again, fix the issue where some color cells aren't clickable
2012-04-01 01:31:38 -07:00
ridiculousfish
51ed3fbc4b More work to try to make webconfig's layout correct under firefox 2012-04-01 00:53:53 -07:00
ridiculousfish
ab78075d06 Default all xterms into term256 2012-04-01 00:53:47 -07:00
ridiculousfish
52070ea577 Fix to properly update colors for non-native term256 support 2012-03-31 17:24:11 -07:00
ridiculousfish
f930303d3e Fix for an issue where you can't select the top row of colors 2012-03-31 15:38:30 -07:00
ridiculousfish
268fb37517 Cleanup proc_had_barrier
Ensure we don't try to do a universal barrier off of the main thread
2012-03-31 15:33:34 -07:00
ridiculousfish
ff17101316 A little better support for non-term-256 colors in web config
Fix for a deadlock when autoloading a function triggers autoloading another function
2012-03-31 15:17:14 -07:00
ridiculousfish
ab536e5199 Fix for incorrectly highlighted parameters 2012-03-31 14:05:14 -07:00
ridiculousfish
c10b3017d6 Improve autosuggesting of cd command 2012-03-30 11:16:24 -07:00
ridiculousfish
0f63e1f988 Some work towards improving manpage completions 2012-03-30 10:00:01 -07:00
ridiculousfish
3bb537c183 Fix for failing to highlight last quote (or quoted string contents) 2012-03-30 09:58:25 -07:00
ridiculousfish
ff23bf6f0c Fix for bug where fish would not autosuggest certain executables 2012-03-27 19:22:33 -07:00
ridiculousfish
00d3e18780 Fix compile error (oops) 2012-03-27 19:10:21 -07:00
ridiculousfish
a62f300753 Make the color picker cell borders appear correctly in Firefox 2012-03-27 19:00:03 -07:00
ridiculousfish
0bc644abf0 Fix lots of bugs related to the static analyzer
Improved how screen.cpp interacts with output_set_writer()
2012-03-26 01:21:10 -07:00
ridiculousfish
31b7d076b7 Remove some dead variables.
Fix screwy output for invalid tilde expansion in expand.cpp
Some cleanup per clang static analyzer
2012-03-25 23:31:03 -07:00
ridiculousfish
a11687fc5c Make the functions builtin have a bit nicer output
Stop autosuggesting things with newlines
Make webconfig a little nicer
2012-03-25 22:41:22 -07:00
ridiculousfish
fa346cec3b Moved some Python scripts into new share/tools/ directory.
Added fish_config function to launch web config
2012-03-25 18:38:33 -07:00
ridiculousfish
0bdf7a598a More work on web_config 2012-03-25 16:00:17 -07:00
ridiculousfish
0c9a1a56c2 Lots of work on web config
Change to make fish immediately show color changes
2012-03-25 16:00:17 -07:00
ridiculousfish
c0655b6b08 Web config 2012-03-25 16:00:17 -07:00
Siteshwar Vashisht
dca9b83ec0 Enclose descriptions inside double quotes, and escape any enclosed double quotes. 2012-03-23 21:34:52 +05:30
Siteshwar Vashisht
7ded90ae6a Add trimmed descriptions with complete command while parsing man pages. 2012-03-22 23:41:36 +05:30
Peter Ammon
a6ab66080e Additional tweak to color order 2012-03-20 11:33:44 -07:00
Siteshwar Vashisht
89e1cad470 Append $argv only to the last command in an alias. 2012-03-20 22:07:34 +05:30
Peter Ammon
e55bc92d1f Tweak the color order 2012-03-20 03:05:00 -07:00
Peter Ammon
d6a59b538f Work on web config color ordering 2012-03-20 03:01:00 -07:00
ridiculousfish
1a87f44325 Re-implement $history variable
Added -L option to set to mean "don't abbreviate"
2012-03-19 11:52:18 -07:00
ridiculousfish
c8bc535f22 Big improvement to web config history speed
Nice dashed table seprators
2012-03-19 11:51:44 -07:00
Peter Ammon
1889db3263 web_config work 2012-03-19 00:03:38 -07:00
Siteshwar Vashisht
73b88f2304 Added method to find a character outside quotes in a string. 2012-03-18 15:14:34 +05:30
Siteshwar Vashisht
21b8e5a5c6 Some additions to make scripted aliases work 2012-03-18 15:00:27 +05:30
ridiculousfish
b1ff14162f More work on web config 2012-03-16 17:21:37 -07:00
Peter Ammon
c6c55823ac More work on web config 2012-03-16 03:05:51 -07:00
ridiculousfish
8b8a970098 Made builtin_test handle parenthesis 2012-03-15 20:40:57 -07:00
Siteshwar Vashisht
ebfcee6e67 Fixed a crash on inputs like ls x>| less, where x doesn't exist in current directory. 2012-03-16 00:34:09 +05:30
Peter Ammon
63b330439e Initial work towards web config UI 2012-03-15 03:43:45 -07:00
ridiculousfish
52d8fb301c Added term256 support to set_color tool 2012-03-13 14:23:10 -07:00
Siteshwar Vashisht
dfe159e719 Fixed a crash on Linux caused while inserting \ in quotes. 2012-03-13 05:39:17 +05:30
Siteshwar Vashisht
4e7e45a431 Adding scripts to import aliases, environment variables and prompt from bash. 2012-03-11 22:46:58 +05:30
ridiculousfish
d81bd296fc Tweak rgb_color_t back down to 4 bytes 2012-03-10 16:15:56 -08:00
ridiculousfish
6d3f257439 Shortened the "no matches found" error message 2012-03-10 13:44:35 -08:00
ridiculousfish
f92b24221a Made pwd a builtin
Fixed a thread error when autosuggesting with a command substitution
2012-03-09 20:16:26 -08:00
ridiculousfish
afd78f3f0b Allow g_log_forks to be set by fish_log_forks env var 2012-03-09 11:56:33 -08:00
ridiculousfish
44f3f51e0d Attempt to not fork just to output the result of simple builtins. I'm unsure of why this was necessary, if it ever was. 2012-03-09 11:49:29 -08:00
ridiculousfish
14a35e7c21 Flip the switch to stop draining threads before exec (!) 2012-03-09 11:28:24 -08:00
ridiculousfish
d173bb6e0a A bunch of changes working towards eliminating all memory allocation after fork() 2012-03-08 23:21:07 -08:00
ridiculousfish
ce859c9e92 Added some missing calls to setup_fork_guards() in utilities.
Made echo a builtin
2012-03-07 11:35:22 -08:00
ridiculousfish
8ed20f3c28 Removed pwd.fish, which made the home directory print out with ~ (annoying) 2012-03-07 10:53:08 -08:00
ridiculousfish
0ced7d8e56 Improve error reporting for builtin_test 2012-03-07 01:16:50 -08:00
ridiculousfish
143ead8d00 Fix builtin_test to properly handle last expression in a combining expression 2012-03-07 01:13:24 -08:00
ridiculousfish
6788c2710f Improved error reporting for builtin_test 2012-03-07 01:02:46 -08:00
ridiculousfish
ed7c10f366 Implemented test as a builtin (!) 2012-03-07 00:54:01 -08:00
ridiculousfish
68b93c624f Move special handling of DISPLAY environment variable from etc/config.fish to fish itself to reduce number of fork calls made at launch 2012-03-06 15:52:16 -08:00
ridiculousfish
36fe1e4a46 Some initial work towards cutting down the number of fork calls we do 2012-03-06 15:12:37 -08:00
ridiculousfish
9ee4e4e05c Tweak fork guards to use getpid() instead of pthread_atfork 2012-03-06 14:34:18 -08:00
ridiculousfish
ea65a0c519 Updated a comment 2012-03-06 14:32:00 -08:00
ridiculousfish
f35d2629d4 Notice when fish_term256 changes and react to it 2012-03-05 14:18:16 -08:00
ridiculousfish
0e5578204e Additional work towards "forcing" term256 mode on supported terms 2012-03-05 13:39:01 -08:00
ridiculousfish
063a465227 Begin to rework term256 support 2012-03-05 10:44:08 -08:00
ridiculousfish
230fb921ec We had identical format_val and to_string; standardize on to_string 2012-03-05 10:18:42 -08:00
ridiculousfish
82a93d8406 Fix for completions only printing one item 2012-03-05 10:03:26 -08:00
ridiculousfish
2dda8634e9 Fix to stop autosuggesting on whitespace 2012-03-05 09:34:54 -08:00
Siteshwar Vashisht
2f313b799a Made fish_tests.cpp compile on Linux. 2012-03-05 21:57:31 +05:30
ridiculousfish
d371256913 Fix for crash on "less test <tab>" 2012-03-04 18:11:21 -08:00
Siteshwar Vashisht
a7ec93b287 Fixed compilation on Linux. 2012-03-04 16:57:41 +05:30
ridiculousfish
2c5001a5b3 Removed buffer_t 2012-03-04 02:45:51 -08:00
ridiculousfish
191221eec5 Final cleanup of io_data_t now that I recognize the bizarre way in which it shares output buffers (not sure how this ever worked before) 2012-03-04 02:35:30 -08:00
ridiculousfish
27f374a38b Some initial work on removing buffer_t from io_data_t 2012-03-03 23:56:35 -08:00
ridiculousfish
baa813c46f Fix for history being saved too often 2012-03-03 23:10:15 -08:00
ridiculousfish
79a22b1f8d Replace some string_buffer_t 2012-03-03 23:01:42 -08:00
ridiculousfish
087940ec9e Fix a bug where wfopen would always fail
Removed some buffer_t
2012-03-03 22:48:21 -08:00
ridiculousfish
8a46931e34 Remove string_buffer_t (!) 2012-03-03 22:08:34 -08:00
ridiculousfish
a9313fc0c3 Cleanup reader.cpp's usage of string_buffer, remove some other unused data structures 2012-03-03 21:59:45 -08:00
ridiculousfish
dfba35aee8 Clean up the kill ring 2012-03-03 21:46:06 -08:00
ridiculousfish
5ae77b4317 For for crash when typing backslash c 2012-03-03 20:38:16 -08:00
ridiculousfish
a0bb2cdc6e removed some string_buffer 2012-03-03 19:37:55 -08:00
ridiculousfish
0a5680c3e8 Rewrite vformat_string to not use string_buffer 2012-03-03 19:12:06 -08:00
ridiculousfish
00764406d7 Fix to preserve errno across certain calls to stop printing EOVERFLOW messages in weird places 2012-03-03 15:28:16 -08:00
ridiculousfish
3ead99b088 Put fish on a diet. Tracked down the biggest memory hogs and fixed them. Total allocations down by a factor of 3 or so, live allocations a few KB. 2012-03-03 15:22:03 -08:00
Siteshwar Vashisht
8c0803e3c5 Setting cdpath to current directory in path.cpp. 2012-03-04 01:28:09 +05:30
ridiculousfish
2da8df6202 Rearrange wopen and stat to avoid a race and hopefully improve performance a little bit. 2012-03-02 11:12:08 -08:00
ridiculousfish
17a75a5aa5 Change to detect and use O_CLOEXEC 2012-03-02 09:58:29 -08:00
Peter Ammon
8b26d0104c Some initial changes to use CLO_EXEC, with an eye towards some day using it correctly. 2012-03-02 00:27:40 -08:00
ridiculousfish
36622c3578 Fix to properly handle case insensitive autosuggestions 2012-03-01 17:31:45 -08:00
ridiculousfish
fd4df6f9bb Changed iterators from iter++ to ++iter
Large set of changes to history to ensure that histories from other sessions don't "bleed" into the current session
2012-03-01 14:56:34 -08:00
ridiculousfish
5d18d60e3b Squash some leaks 2012-02-29 18:09:20 -08:00
ridiculousfish
e4d98597c7 Added some fork tests, fixed some bugs it found 2012-02-29 17:55:50 -08:00
ridiculousfish
72da14e414 Fix a leak 2012-02-29 17:55:28 -08:00
ridiculousfish
8ada404c5f More work towards improving relationship between multithreading and fork 2012-02-29 16:14:51 -08:00
ridiculousfish
ebba30d671 Fix a "class <-> struct" warning with clang++ 2012-02-29 16:14:51 -08:00
ridiculousfish
909d24cde6 More work on improving interaction between fork and pthreads. Added null_terminated_array_t class. 2012-02-29 16:14:51 -08:00
ridiculousfish
4e912ef83d Added postfork 2012-02-29 16:14:51 -08:00
ridiculousfish
b17dfff3fd Fix for out-of-bounds write in highlight_param 2012-02-29 16:14:03 -08:00
ridiculousfish
52dc415d0b Fix to add a generation count to threaded operations so they abort early 2012-02-28 12:40:59 -08:00
Siteshwar Vashisht
392232246e Fixed compilation on Linux with some minor changes. 2012-02-28 21:20:09 +05:30
ridiculousfish
cf54ad8242 Change to wait for all outstanding iothreads before calling fork(). This should prevent a whole host of threading/fork interactions, but may also compromise performance...we'll see. 2012-02-27 19:46:15 -08:00
ridiculousfish
fdfa5c0602 Some initial work towards resolving nasty fork/pthread issues, and to having a per-parser job list 2012-02-27 18:43:24 -08:00
ridiculousfish
50ee5d28cd Fix to finally turn on multithreaded completions for autosuggestion 2012-02-27 15:33:46 -08:00
ridiculousfish
f74a82776f Some more changes in preparation for turning on complete-based autosuggestions 2012-02-26 20:11:34 -08:00
ridiculousfish
3553e65089 Add some more locking and const correctness to completion_entry_t in preparation for supporting better multithreading 2012-02-26 14:32:06 -08:00
ridiculousfish
ad7c5886bc Fix a crash in complete -C 2012-02-26 13:46:21 -08:00
ridiculousfish
b30090f946 Some cleanup of completions in preparation for more multithreading 2012-02-26 13:27:31 -08:00
ridiculousfish
8f637975a4 Temporarily disable background completions 2012-02-26 12:16:22 -08:00
ridiculousfish
94a764d6ea Fix for error messages when loading completions 2012-02-26 01:15:53 -08:00
ridiculousfish
38e40862fe More work towards autosuggesting completions 2012-02-25 18:54:49 -08:00
ridiculousfish
5ea78f55f2 Some more work on threaded completions 2012-02-24 18:43:10 -08:00
ridiculousfish
a515db4aea Some work to allow completions to be evaluated off of the main thread 2012-02-24 12:19:31 -08:00
ridiculousfish
90e979d0d9 Added some const correctness 2012-02-24 09:33:30 -08:00
Siteshwar Vashisht
8232857d07 Modified env_get_string() to accept wcstring instead of wchar_t*. 2012-02-24 00:58:01 +05:30
ridiculousfish
2ae56564ef Changes to block signals for a smaller time interval during saving 2012-02-23 10:49:30 -08:00
ridiculousfish
f24a0170be Fix for failing to unescape history properly, resulting in a backslash explosion 2012-02-23 10:29:42 -08:00
Siteshwar Vashisht
fd56465931 Fixed initialization of va_list variable in debug() in common.cpp, and mismatched new/free() in io.cpp 2012-02-23 23:10:51 +05:30
ridiculousfish
376e199ebb Removed a lot of string_buffer_t 2012-02-22 12:00:02 -08:00
ridiculousfish
a837a27b34 Replace some string_buffer_t with wcstring 2012-02-22 11:07:34 -08:00
ridiculousfish
62bd43f17f Large set of changes to migrate sb_out and sb_err to wcstring 2012-02-22 10:51:06 -08:00
ridiculousfish
917b4ff8bc Fix for crash on redirections 2012-02-21 19:39:29 -08:00
ridiculousfish
5fe7c065dc Squash a bunch of leaks 2012-02-21 19:33:11 -08:00
ridiculousfish
e074ad4807 Removed a leaking wcsdup 2012-02-21 18:18:10 -08:00
ridiculousfish
5f3fe4acff Removed an optimization obviated by our use of wcstring from env.cpp 2012-02-21 18:12:51 -08:00
ridiculousfish
4ccc197451 Fix to change highlighting functions to take wcstring& instead of const wchar_t * 2012-02-21 17:55:56 -08:00
ridiculousfish
237cf19a77 Switch to using std::vector instead of int* for colors in highlight.cpp, for better range bounds checking 2012-02-21 11:45:13 -08:00
ridiculousfish
2206e221bd Removed array_list_t (!) 2012-02-21 10:47:21 -08:00
ridiculousfish
d9bb9b73ad Change to allow building without doxygen 2012-02-20 16:18:10 -08:00
ridiculousfish
d5c382bb1a Piling on more code to make autosuggestion try to guess directories even when they're not in the history 2012-02-20 02:13:31 -08:00
Peter Ammon
52daf6cf41 Fix to allow color.cpp to use fallback wcscasecmp 2012-02-19 11:07:02 -08:00
Siteshwar Vashisht
74a7303c23 Modified functions in function.h/.cpp to use wcstring instead wchar_t*, other files also modified to use wcstring. 2012-02-19 22:55:15 +05:30
ridiculousfish
d8a9991738 Fix to avoid calling signal_block off of hte main thread 2012-02-18 23:26:39 -08:00
ridiculousfish
ca1c8243c8 Fix to prevent autosuggesting cd'ing to the current working directory 2012-02-18 21:56:30 -08:00
ridiculousfish
14b3a5be56 Changes to make autosuggestion even smarter by specially recognizing the cd command. 2012-02-18 18:54:36 -08:00
ridiculousfish
ed89df7e9d Some minor cleanup of reader.cpp in preparation to unify highlighting with autosuggestion 2012-02-18 18:51:11 -08:00
ridiculousfish
1bedc16544 Enhanced directory detection in a way we don't actually need yet 2012-02-18 18:51:11 -08:00
ridiculousfish
ac0b97a571 Squash some warnings 2012-02-18 18:49:55 -08:00
Siteshwar Vashisht
7b3d670e23 Removing some unnecessary calls to c_str(), and added str2wcstring(std::string) in common.cpp. 2012-02-18 23:28:54 +05:30
Siteshwar Vashisht
c9f4e91df8 Modified most functions in wutil.h/.cpp to use wcstring instead of wchar_t*, removing calls to c_str() while calling these functions in other files. 2012-02-18 22:41:22 +05:30
Siteshwar Vashisht
c0ed169fdc Getting rid of hash_table_t and it's helper functions completely. Bye bye hash_table_t ! 2012-02-18 21:21:10 +05:30
Siteshwar Vashisht
412894bfc8 Removed tests for hash_table_t from fish_tests.cpp 2012-02-18 21:04:09 +05:30
Siteshwar Vashisht
aad6e5648b Fix for properly removing universal variable. 2012-02-18 14:42:02 +05:30
ridiculousfish
8f1423946f Fix a crash when using quotes due to wgettext thread safety issues. 2012-02-17 15:55:54 -08:00
ridiculousfish
51da4856e2 Squash a leak in LRU caches 2012-02-17 14:54:58 -08:00
ridiculousfish
3b56c58f00 Fix for crash in env.cpp where a deleted entry was not removed from the map 2012-02-17 12:23:30 -08:00
ridiculousfish
4fd2531302 Fix to properly null-terminate export list 2012-02-17 11:42:53 -08:00
ridiculousfish
fdef238a83 Fix to stop spamming console with event messages (oops) 2012-02-17 11:40:26 -08:00
ridiculousfish
9787901ddb Fix for removing too many event handlers (that's why "Goodbye" never got printed") 2012-02-17 11:37:25 -08:00
Siteshwar Vashisht
6e58c9f7c8 Switched to std::map instead of hash_table_t in env.cpp and env_universal_common.cpp. 2012-02-18 00:25:29 +05:30
ridiculousfish
a08450bcb6 Changes to make autosuggestion smarter about not suggesting commands that could never succeed. 2012-02-16 00:24:27 -08:00
ridiculousfish
a92d9d442b Initial work towards making autosuggestion smarter by recognizing paths 2012-02-15 11:33:41 -08:00
ridiculousfish
e2ff77b4ec Clean up make_path and some memory allocations 2012-02-13 22:44:29 -08:00
ridiculousfish
caf7a93382 Fix for busted completions (tab completion of directories was failing) 2012-02-13 22:37:09 -08:00
ridiculousfish
afcda2f724 Fix a leak 2012-02-13 19:39:20 -08:00
ridiculousfish
fcea723aa7 Fixed parenthesis causing a crash or bizarre layout. 2012-02-13 17:15:41 -08:00
ridiculousfish
faf80588ab Fix for busted directory check 2012-02-13 16:38:35 -08:00
ridiculousfish
fc589611e2 Attempt to make fish_pager.cpp compile on Linux 2012-02-13 14:25:07 -08:00
ridiculousfish
5ecd350311 Another attempt to make mimedb.cpp compile on Linux 2012-02-13 14:22:07 -08:00
ridiculousfish
4b6c6c59b5 Squash warnings in mimedb, hopefully get it compiling on Linux 2012-02-13 12:14:26 -08:00
ridiculousfish
0f8ffa6226 For for crash printing backtrace for command "eval cd sldkfjsdlfk" 2012-02-13 11:55:02 -08:00
ridiculousfish
6def61dfe9 A bit more debugging to parser class to try to track down a crash 2012-02-13 11:42:58 -08:00
ridiculousfish
b39bebee06 Fix for problem where we'd never use a cached placeholder function. Also upped the staleness interval from its testing value of 1 to 15 seconds. 2012-02-13 10:28:04 -08:00
ridiculousfish
dce189fc6d Support for setting both RGB and named colors on the same line, so the same config can work for multiple term types 2012-02-13 09:52:17 -08:00
ridiculousfish
0a4c72e78b Added color.h, color.cpp. Got term256 colors working. 2012-02-12 18:05:59 -08:00
ridiculousfish
d66700a0e4 Color work 2012-02-11 17:07:56 -08:00
ridiculousfish
b59a22bef0 Colors 2012-02-10 17:57:20 -08:00
ridiculousfish
9b1930588f Migrate errors from array_list_t to wcstring_list_t 2012-02-10 17:54:38 -08:00
Siteshwar Vashisht
18bb64cd43 Fixed compilation with recent changes on Linux. 2012-02-10 21:25:06 +05:30
ridiculousfish
d975187433 Removed some al_list functions 2012-02-10 01:37:30 -08:00
ridiculousfish
910863e9ea Final removal of halloc. It's like Christmas Morning. 2012-02-09 19:26:44 -08:00
ridiculousfish
a38490429b Removed a halloc_register_function_void 2012-02-09 19:00:05 -08:00
ridiculousfish
80e8f6a0d1 Removed halloc_wcsdup 2012-02-09 18:59:15 -08:00
ridiculousfish
e5ff5f7484 Some hopefully good changes to get IOs off of halloc 2012-02-09 18:43:36 -08:00
ridiculousfish
646240fc54 Changed the Makefile to no longer fail if man pages are missing, etc. 2012-02-09 16:36:35 -08:00
ridiculousfish
19cd7a248d Cleanup of wildcard.cpp, removing ad-hoc hash table and halloc 2012-02-09 16:06:24 -08:00
ridiculousfish
f1b1d1ca75 Get rid of some string buffer 2012-02-09 10:14:06 -08:00
ridiculousfish
e5bba2294d Removed some more halloc 2012-02-09 02:01:49 -08:00
ridiculousfish
19cfd9b5d6 Fix for pager regression 2012-02-09 01:54:46 -08:00
ridiculousfish
7e1b15a0cc More changes to fish pager to fix regressions. It didn't actually work. 2012-02-09 01:39:08 -08:00
ridiculousfish
19858c574d Removed halloc and al_list from fish_pager. paging still seems to work 2012-02-09 01:02:12 -08:00
ridiculousfish
f891ea5713 Fixed named_arguments to be wcstring_list_t instead of al_list 2012-02-08 23:53:23 -08:00
ridiculousfish
d3311c81e5 REmoved al_list from exec.cpp 2012-02-08 22:56:42 -08:00
ridiculousfish
b6bc4381fb Get event_t off of halloc (!) 2012-02-08 19:02:25 -08:00
ridiculousfish
b3d0561c09 Cleanup event_get_desc 2012-02-08 16:20:48 -08:00
ridiculousfish
1bbe901bcd Eliminated halloc usage from complete.cpp 2012-02-08 16:15:53 -08:00
ridiculousfish
4f8b4379f5 Cleanup of completion_entry in complete.cpp 2012-02-08 14:48:22 -08:00
Siteshwar Vashisht
bc8a288386 Got rid of multiple cd paths, only current directory will be searched while changing directories, implicit cd (entering directory just by typing it's name) is removed. 2012-02-09 01:18:51 +05:30
ridiculousfish
3dc56de0ae Excised some more halloc and array_list_t 2012-02-08 02:34:31 -08:00
ridiculousfish
b2e5809180 Removed halloc from highlight.cpp 2012-02-08 02:13:39 -08:00
ridiculousfish
7e52523541 Migrate mimedb off of al_init 2012-02-08 01:55:35 -08:00
ridiculousfish
8bc83c5967 Removed al_list from mimedb.cpp 2012-02-08 01:22:08 -08:00
ridiculousfish
029c8c06c2 Remove old env_get_names implementation 2012-02-08 00:59:46 -08:00
ridiculousfish
063fc0c48b Cleanup al_list from builtin_complete.cpp 2012-02-08 00:45:07 -08:00
ridiculousfish
191eeab589 Cleanup expand_escape_variable 2012-02-08 00:15:06 -08:00
ridiculousfish
3f8621e566 CLeanup the io_stack in builtin.cpp, other changes to migrate away from al_list 2012-02-07 23:53:34 -08:00
ridiculousfish
5f686ebb47 Clean up exec_subshell, removing al_list from it 2012-02-07 23:35:41 -08:00
ridiculousfish
6a31457c6d Really excise halloc from input.cpp 2012-02-07 23:17:20 -08:00
ridiculousfish
e6f7912a25 Removed halloc from input.cpp 2012-02-07 23:15:32 -08:00
ridiculousfish
8a2737566c Excised some more halloc 2012-02-07 22:44:10 -08:00
ridiculousfish
006523ac59 Replaced void*data with auto_ptr<function_data_t>, eliminating antoher halloc. 2012-02-07 22:10:35 -08:00
ridiculousfish
c0e783eb6e Excised some halloc 2012-02-07 21:23:12 -08:00
ridiculousfish
399c78fbf7 Fix event_block_t list from ad-hoc linked list to std::dequeue 2012-02-07 21:04:51 -08:00
ridiculousfish
a0a43046b3 Removed discriminated union from block_t type, allowing us to store wcstrings in it 2012-02-07 17:36:54 -08:00
Siteshwar Vashisht
e8af86017a Fixed a bug caused while highlighting double quoted strings. For e.g. ls "abc" shows up as invalid write for color of closing quote in valgrind. 2012-02-07 21:37:53 +05:30
ridiculousfish
382ffe9b6a Added autosuggestion color variable fish_color_autosuggestion
Fixed that nasty bug where fish would apply a color to both the foreground and background (yuck)
2012-02-06 20:14:19 -08:00
ridiculousfish
e5b34d5cd5 Suppress autosuggesting during backspacing like browsers do 2012-02-06 19:31:06 -08:00
ridiculousfish
0dba7b3313 Use right arrow to accept autosuggestions 2012-02-06 11:59:34 -08:00
ridiculousfish
27f2859258 Make history searching skip the autosuggestion 2012-02-06 11:52:24 -08:00
ridiculousfish
eeed45da0f Fix some bugs related to not updating our buffer size as our command line changes 2012-02-06 11:34:49 -08:00
ridiculousfish
067dff8489 Initial stab at autosuggestions 2012-02-06 10:52:13 -08:00
ridiculousfish
7d3151191d Removed builtin_scripts.h and builtin_scripts.cpp from Xcode project because they're annoying in searches 2012-02-06 10:47:55 -08:00
ridiculousfish
98fa1325f5 insert_str -> insert_string 2012-02-06 02:20:50 -08:00
ridiculousfish
bd45b79ed8 Removed buff_len field. One fewer field, hooray. 2012-02-06 01:53:03 -08:00
ridiculousfish
0a616a9dbb Large set of changes to migrate reader_data_t's buffer to std::wstring 2012-02-06 01:45:16 -08:00
ridiculousfish
a534c397f5 Const correctness changes 2012-02-06 00:57:43 -08:00
ridiculousfish
737589ec01 Removed lru.cpp (double oops) 2012-02-06 00:53:08 -08:00
ridiculousfish
a7f8ee90c0 Added LRU.cpp (oops) 2012-02-06 00:52:22 -08:00
ridiculousfish
b14683200a Change the history so that when you go forwards, it no longer highlights 2012-02-05 23:22:18 -08:00
ridiculousfish
c82410bfda Fixed history tests 2012-02-05 22:48:43 -08:00
ridiculousfish
00ad837eb4 Final cleanup of history 2012-02-05 22:30:42 -08:00
ridiculousfish
9ab54030b9 Moved LRU to its own file 2012-02-05 20:54:41 -08:00
ridiculousfish
5ad6849d4e Work on new history implementation 2012-02-05 16:42:24 -08:00
ridiculousfish
7fcf25a78f Removed the "don't highlight with stale data" code, that caused "flashing" as we typed 2012-02-03 20:06:48 -08:00
ridiculousfish
5c205c43d1 Fix to highlight search results range matching again 2012-02-03 20:05:50 -08:00
ridiculousfish
f20f49d872 Migrate search_buff to wcstring 2012-02-03 20:01:01 -08:00
ridiculousfish
fb63c3908c Minor cleanup of background_highlight_context_t 2012-02-03 18:39:41 -08:00
ridiculousfish
623eb42a6a CLean up current_filename, make it a std::stack 2012-02-02 15:05:08 -08:00
ridiculousfish
6afc06b97e Migrate some al_list to std::vector 2012-02-02 14:27:13 -08:00
ridiculousfish
cdd5b1ed26 Fixed a crash doing completion of commands 2012-02-02 14:11:20 -08:00
ridiculousfish
884b4026dd Cleanup complete_cmd_desc 2012-02-02 12:04:04 -08:00
ridiculousfish
62f49c55ce Clean up uses of completion_t 2012-02-01 16:27:14 -08:00
ridiculousfish
0b4b6c498d Migrated off of old variant of expand_one that used halloc 2012-01-31 21:30:09 -08:00
ridiculousfish
409f70c7f3 Remove some old functions from expand.cpp that now have modern replacements 2012-01-31 21:09:11 -08:00
ridiculousfish
bb19fe703a Fixup wsetlocale to use wcstring 2012-01-31 21:06:52 -08:00
ridiculousfish
eef1e3e77e More cleanup of static string buffers in favor of wcstring 2012-01-31 20:22:25 -08:00
ridiculousfish
562ba1291e Stop using placement new like a weirdo 2012-01-31 20:03:48 -08:00
ridiculousfish
3adf6d25f6 Cleanup of builtins. No more hashes. 2012-01-31 19:47:56 -08:00
ridiculousfish
beece6a828 Clean up how argv is stored in process_t 2012-01-31 18:06:20 -08:00
ridiculousfish
207ab2aa5b Squashed all known remaining leaks! 2012-01-31 17:06:47 -08:00
ridiculousfish
4ccc2550d0 Squash a bunch of warnings 2012-01-31 17:01:19 -08:00
ridiculousfish
0c9e398bef Change parser_t::parse_job's args array to be a local, rather than just leak it, which no longer seems to crash 2012-01-31 16:50:03 -08:00
ridiculousfish
af2d348543 Substantial modifications of expand_variables to modernize, normalize memory management, adopt C++ types 2012-01-30 21:33:15 -08:00
Jan Kanis
23bc10dfe6 Add stddef.h to util.c, so ptrdiff_t is defined in all environments 2012-01-31 01:38:20 +01:00
ridiculousfish
13f72decf4 Fix a leak 2012-01-30 11:23:09 -08:00
ridiculousfish
3ad7de0fcb Fix some leaks and clean up expand_pid to use wcstring 2012-01-30 11:15:06 -08:00
Siteshwar Vashisht
48408b0a0b Merge branch 'CPlusPlus' of gitorious.org:~ridiculousfish/fish-shell/fishfish into CPlusPlus 2012-01-31 00:04:15 +05:30
Siteshwar Vashisht
cd7d1f2bfe Fix to not show thread debugging warning when entering characters like "~%". expand_string2() now uses it's own parser instead of principal_parser. Added PARSER_TYPE_ERRORS_ONLY in parser_type_t. 2012-01-30 23:58:30 +05:30
ridiculousfish
ed66a46113 Fix for is_potential_path that caused all strings to be reported as paths 2012-01-30 09:59:48 -08:00
ridiculousfish
8e4e30d266 Migrate functions like parser_keywords_is_block to wcstring 2012-01-30 09:46:33 -08:00
Siteshwar Vashisht
f988dcd6f9 Fixed compilation errors caused by latest commits 2012-01-30 21:45:02 +05:30
ridiculousfish
143091edad More work to excise halloc 2012-01-30 02:45:55 -08:00
ridiculousfish
79e0405f6a Yet more un-hallocing 2012-01-30 02:23:58 -08:00
ridiculousfish
316f81119f Excised some more halloc 2012-01-29 23:22:42 -08:00
ridiculousfish
8d016040ab Back out removing a halloc_register to fix a leak 2012-01-29 22:32:01 -08:00
ridiculousfish
4da6986a68 Fix to finally make builtin_scripts.h and builtin_scripts.cpp be generated by the Makefile 2012-01-29 22:29:13 -08:00
ridiculousfish
3b8a4e56b0 A bunch of work to move towards a sane memory model in job_t 2012-01-29 22:06:58 -08:00
ridiculousfish
966cd6a8ca Began migration of job_t away from halloc 2012-01-29 18:25:54 -08:00
ridiculousfish
f243cd86c9 Convert jobs list to std::list 2012-01-29 16:36:21 -08:00
Siteshwar Vashisht
1a5d866a91 buggy-auto-complete is not so buggy now. Merged branch 'buggy-auto-complete' into CPlusPlus 2012-01-29 14:11:39 +05:30
Siteshwar Vashisht
a1d8ed83dd Putting a copyright statement on my script :) 2012-01-29 13:02:40 +05:30
Peter Ammon
7f284c404f Fixed for comment in create_manpage_completions.py to refer to new filename 2012-01-28 22:48:47 -08:00
ridiculousfish
d1b3b6a0ed Added create_manpage_completions.py file for generating completions from man pages 2012-01-28 22:25:45 -08:00
ridiculousfish
9b37bc667f Fix for issue where we treated all cached files as accessible for the purpose of highlighting, instead of using their cached accessible variable 2012-01-28 15:49:50 -08:00
ridiculousfish
4eea68b5a4 LRU work to load functions off of the main thread.
We'll have to reevaluate this after we fix function autocomplete
2012-01-28 14:56:13 -08:00
ridiculousfish
87429bc03c More work on LRU cache and adopting it in function and completion autoloading 2012-01-27 11:43:52 -08:00
ridiculousfish
6c28448e84 Added LRU tests, and made tests work again 2012-01-27 11:43:45 -08:00
ridiculousfish
843ba4ac2c Move autoload class into autoload.h and cpp 2012-01-25 18:59:35 -08:00
ridiculousfish
d6545588a3 Have to remember to evict nodes from our LRU cache 2012-01-25 18:51:26 -08:00
ridiculousfish
26b375a0de Removed access_tracker since we don't need it after all 2012-01-25 18:42:41 -08:00
ridiculousfish
2f1cac604d Implemented LRU cache for autoloading. 2012-01-25 18:40:08 -08:00
ridiculousfish
8e56763c98 LRU cache work 2012-01-25 11:47:45 -08:00
ridiculousfish
e94e1cc72f New file autoload.h that will ultimately handle autoloading completions and functions 2012-01-25 00:36:55 -08:00
Jan Kanis
8ae00697c9 Merge branch 'merge-requests/14' 2012-01-25 01:21:14 +01:00
Jan Kanis
b0c6d891e9 reviewed merge reqest 14:
* fixed some whitespace inconsistencies
* changed variable handling in __fish_complete_subcommand_root
2012-01-25 01:14:47 +01:00
Jan Kanis
548164cd5e do not escape 'commandline' output without the -o flag 2012-01-25 00:11:00 +01:00
ridiculousfish
4dfe36feb1 Migrate input_function_get_names to wcstring_list_t 2012-01-23 20:48:47 -08:00
ridiculousfish
0d1c2a3b2a Migrated function.cpp to use the new function_get() call. Lots of nice short code now. 2012-01-23 20:43:39 -08:00
ridiculousfish
378fd60756 Migrate function.cpp to scoped_lock and shared_ptr 2012-01-23 20:32:36 -08:00
ridiculousfish
fa569b32fb Made intern'd strings thread safe.
Removed intern_free_all().
2012-01-23 20:02:15 -08:00
ridiculousfish
78f8317de8 Typo fixes 2012-01-23 19:33:57 -08:00
ridiculousfish
6e8637fbc9 Move autoloading from a map of path names to a real object autoload_t.
Moved the various things we can autoload into static objects.
Next step is to make them thread safe.
2012-01-23 11:42:41 -08:00
ridiculousfish
8403aae928 Convert some cases where parsers are created to using PARSER_TYPE_GENERAL 2012-01-22 21:57:30 -08:00
ridiculousfish
b43c8da66b More work towards instanced parser. First successful compilation 2012-01-22 21:40:08 -08:00
ridiculousfish
da85bdc401 More work on the instanced parser 2012-01-22 20:47:13 -08:00
ridiculousfish
7e486e3b5c More work towards instanced parser 2012-01-20 11:24:43 -08:00
Siteshwar Vashisht
062e423125 Fixed more known auto completion bugs; auto completion calls working fine now 2012-01-20 22:20:31 +05:30
ridiculousfish
3d8face1f9 More work on instancing the parser 2012-01-19 10:28:44 -08:00
Siteshwar Vashisht
0c99fc5b4d Removed unnecessary const_cast in wildcard.cpp 2012-01-19 22:23:25 +05:30
Siteshwar Vashisht
51d7d5d0da Fixed calls to expand_variables2() in expand.cpp 2012-01-19 21:49:24 +05:30
Siteshwar Vashisht
c959584831 Fixed reader.cpp to not show garbage while showing help on auto completing (on pressin tab) for executables like "ls -" 2012-01-19 00:03:19 +05:30
ridiculousfish
fa796d668f Get some basic function signatures right for new instanced parser 2012-01-16 12:10:08 -08:00
ridiculousfish
e4ee4ec3d1 Some const correctness 2012-01-16 11:16:12 -08:00
ridiculousfish
0073a93079 Beginnings of instance parser work 2012-01-16 11:09:19 -08:00
Siteshwar Vashisht
7e124cf95e Added constructor to completion_t for guarranted initialzation of flags attribute. 2012-01-16 23:54:57 +05:30
ridiculousfish
c647bed9d5 Fix for bogus check for IFS environment variable 2012-01-16 09:43:34 -08:00
Siteshwar Vashisht
6f330f961b Merge branch 'CPlusPlus' of gitorious.org:~ridiculousfish/fish-shell/fishfish into CPlusPlus 2012-01-16 22:27:55 +05:30
Siteshwar Vashisht
140ead65b6 Converted all auto completion calls (on pressing tab) to use std::vector<completion_t>, bugs are yet to be fixed 2012-01-16 22:26:47 +05:30
ridiculousfish
f12fd3707e Added a missing header for ptrdiff_t 2012-01-15 15:23:05 -08:00
ridiculousfish
55091d9deb Fix to prevent autoloading of completions on highlight thread 2012-01-15 14:24:58 -08:00
Peter Ammon
1b3427acd9 Changes to make completions internalized scripts.
This about doubles the size of fish. These things are huge. We may not want to ship it like this.
2012-01-15 00:25:21 -08:00
Peter Ammon
60d1ac4fec More const and signed correctness. Warnings now fit on one page! 2012-01-14 22:48:53 -08:00
Peter Ammon
9b133a978d Improve const and signed/unsigned correctness 2012-01-14 22:32:45 -08:00
Peter Ammon
203c749e6c Improved const-correctness, eliminating warnings.
Migrated some int to size_t
2012-01-14 22:00:00 -08:00
Peter Ammon
f3e2d2f68f Lots of warnings fixes and const correctness 2012-01-14 03:41:50 -08:00
Peter Ammon
a359f45df2 Redesign new environment variables to use env_var_t instead of wcstring
Migrate uses of empty() to missing() to distinguish between empty variable and unset variable
2012-01-14 02:42:17 -08:00
Peter Ammon
e8b6d48ad0 Introduce env_var_t to replace empty string as missing environment variable 2012-01-14 01:06:47 -08:00
ridiculousfish
8ba79d6ab9 Migrate function.cpp to STL types. 2012-01-13 23:54:49 -08:00
ridiculousfish
57c9eeeecb Changes related to supporting "intern scripts." These are scripts that used to be installed in /share/functions, but now are just compiled-in strings. This should reduce the amount of I/O done at launch time. 2012-01-13 23:54:16 -08:00
Siteshwar Vashisht
f78c4fa751 Removed multiple delcartions of path_list from autoload_names() in fuction.cpp 2012-01-14 12:06:16 +05:30
Siteshwar Vashisht
3ba6e9db5d Merge branch 'Use_env_get_string' into CPlusPlus
Conflicts:
	function.cpp
2012-01-14 11:59:48 +05:30
Siteshwar Vashisht
610246c48f Modified function.cpp to use env_get_string(). 2012-01-12 23:22:38 +05:30
Siteshwar Vashisht
d0e18e3d20 Modified highlight.cpp to use env_get_string(). 2012-01-12 23:19:05 +05:30
Siteshwar Vashisht
72cfdbbb4e Modified input.cpp, output.cpp to use env_get_string() 2012-01-12 23:11:07 +05:30
Siteshwar Vashisht
15296dedd5 Modified kill.cpp to use env_get_string(). 2012-01-12 23:07:10 +05:30
Siteshwar Vashisht
943cc68f54 Modified parse_util.cpp, parser.cpp, path.cpp to use env_get_string() 2012-01-12 22:56:53 +05:30
Siteshwar Vashisht
3bb4d0b276 Modified reader.cpp to use env_get_string() 2012-01-12 22:32:50 +05:30
Siteshwar Vashisht
9cc2217a26 Fixed connection error to fishd server in env.cpp 2012-01-12 21:58:42 +05:30
Siteshwar Vashisht
ee687ee433 Modified exec.cpp to use env_get_string(); rolled back changes to expand.cpp in last commit, because pressing ^D results into an error with the changes 2012-01-12 21:39:00 +05:30
Siteshwar Vashisht
9b56b67c0e Revert "Modified expand.cpp and exec.cpp to use env_get_string()"
This reverts commit 48655e882e.
2012-01-12 04:21:11 +05:30
Siteshwar Vashisht
48655e882e Modified expand.cpp and exec.cpp to use env_get_string() 2012-01-12 04:19:04 +05:30
Siteshwar Vashisht
7f49d37a51 Modified exec.cpp to use env_get_string() 2012-01-12 04:01:08 +05:30
Siteshwar Vashisht
9f8a1168e6 Modified env.cpp to use env_get_string() 2012-01-12 03:57:38 +05:30
ridiculousfish
c18d177b8c Additional migration to STL data structures 2012-01-10 12:55:22 -08:00
Siteshwar Vashisht
7bde2b5cbf Modified complete.cpp to use env_get_string(); Fixed env_get_string() return an empty wcstring instead of returning 0. 2012-01-10 01:40:03 +05:30
Siteshwar Vashisht
7b3377e78c Modified builtin_set.cpp to use env_get(), added functions like update_values2(), env_set2() etc. to support wcstring and vector instead of using array_list_t 2012-01-10 01:19:37 +05:30
Siteshwar Vashisht
feed900f3d Further changes in builtin.cpp to use env_get_string() 2012-01-10 00:05:51 +05:30
Siteshwar Vashisht
7530057c6e Modified builting.cpp to use env_get_string() 2012-01-10 00:00:54 +05:30
Siteshwar Vashisht
a6b3f6b5d4 Modified screen.cpp to compile on Linux. 2012-01-07 16:35:49 +05:30
ridiculousfish
76f870a30a Improved check for pthread library to build successfully on Linux 2012-01-06 11:50:17 -08:00
ridiculousfish
02092f315e More work towards incorporating C++ build steps into Makefile.in and configure.ac 2012-01-06 11:29:03 -08:00
ridiculousfish
9ef9284a34 Fix for bogus cast warning in configure script that was breaking local_cv_use__posix_c_source 2012-01-06 10:43:27 -08:00
ridiculousfish
820acb981b Fix to incorporate C++ build changes into configure.ac and Makefile.in 2012-01-06 10:23:38 -08:00
ridiculousfish
2516fd90eb Updated dependencies in Makefile.in 2012-01-05 14:10:02 -08:00
ridiculousfish
de23368d03 Updated Makefile.cpp with updated header dependencies 2012-01-05 14:06:09 -08:00
ridiculousfish
4df57fda09 Incorporate Siteshwar's patch for building on Linux 2012-01-05 13:58:48 -08:00
ridiculousfish
6f45832aed Switch from std::set to std::map in parse_util.cpp 2012-01-04 17:56:02 -08:00
ridiculousfish
fec0415d4e Rewrote parse_util.cpp data structures to use STL types and classes 2012-01-04 17:40:36 -08:00
ridiculousfish
04c7d87261 More work towards supporting builtin scripts 2012-01-03 10:54:06 -08:00
ridiculousfish
6abf3db13e Added internalize_scripts.py in preparation for ending reliance on "standard" scripts in /usr/local/share 2012-01-02 17:02:30 -08:00
ridiculousfish
99000e68b7 Fix for crash when unescaping a string with unbalanced quotes
Add Mac OS X's default term name to terms for which we know how to set a title
2012-01-02 13:40:03 -08:00
ridiculousfish
bef046a51a More work to migrate off of ad-hoc data structures 2011-12-31 15:57:30 -08:00
ridiculousfish
78322a6321 Migrate some more away from array_list_t 2011-12-28 12:36:47 -08:00
ridiculousfish
46fa2dd2f0 Migration of screen away from ad-hoc lists 2011-12-27 18:41:38 -08:00
ridiculousfish
451399b344 Migrate to std::vector in event class 2011-12-27 00:06:07 -08:00
ridiculousfish
22a8e57a57 More migration away from al_list 2011-12-26 23:29:57 -08:00
ridiculousfish
9cd279e0e9 Migrate some more off of al_list 2011-12-26 23:13:05 -08:00
ridiculousfish
b67eaa3abd More migration to the STL 2011-12-26 22:51:34 -08:00
ridiculousfish
046c9b56f5 Migrate blocked to std::vector 2011-12-26 22:27:58 -08:00
ridiculousfish
6ad80247ce Migrate killme to std::vector 2011-12-26 22:22:55 -08:00
ridiculousfish
0b744edfa4 Migrate events to std::vector 2011-12-26 22:18:16 -08:00
ridiculousfish
0d8bb78f66 Fixed a build failure
Added a thread assertion to function.cpp
2011-12-26 21:56:23 -08:00
ridiculousfish
28ecc68841 Migrated some more data structures to the STL. Removed some ad-hoc data structure implementations. 2011-12-26 21:50:23 -08:00
ridiculousfish
7c7aba1202 Fix to migrate the universal variable server off of dyn_queue_t 2011-12-26 21:39:08 -08:00
ridiculousfish
74a1d70b8a Added iothread 2011-12-26 21:21:12 -08:00
ridiculousfish
165a5aaa83 Merge branch 'master' into CPlusPlus 2011-12-26 21:09:26 -08:00
ridiculousfish
8b407a32ff Fix to use proper type to compute difference between two pointers, which fixes a crash when fish is compiled LP64 2011-12-26 21:08:45 -08:00
ridiculousfish
04856aded0 IO port 2011-12-26 21:05:25 -08:00
ridiculousfish
a9c238a1fc Removed a log 2011-12-26 21:05:07 -08:00
ridiculousfish
8d2f107d61 Some changes to migrate towards C++ and a multithreaded model 2011-12-26 19:18:46 -08:00
ridiculousfish
3f16ace678 Initial C++ conversion 2011-12-26 19:11:54 -08:00
Jan Kanis
344b9bdba3 Merge branch 'master' into merge-requests/14 2011-12-17 14:19:29 +01:00
Jan Kanis
834ea94eb9 update aptitude completions, patch by Dániel Ugra, closes Launchpad bug 238282 2011-09-25 01:24:34 +02:00
Jan Kanis
a060cc5893 uniq doesn't filter duplicates that aren't consecutive, use sort -u 2011-09-23 21:59:50 +02:00
gonchar
7ef0b3b821 *wvdial completion fixed 2011-09-23 18:40:14 +04:00
gonchar
39a2fd1717 * git rm and git status options are added
* ssh subcomand completion
* __fish_complete_subcommand now can skip variable number of tokens
2011-09-23 14:51:14 +04:00
gonchar
c66ec4df3d * __fish_complete_subcommand_root now passes arguments to
__fish_complete_subcommand

* sudo:
  - now can be completed bu group and user (-u and -g keys).
  - subcommand completion is fixed

* __fish_complete_proc.fish is added to complete killall command with
  list of running processes

* __fish_complete_tex.fish is updated with common options

* __fish_make_completion_signals.fish is added to make a list of kill
  signals for kill and killall

* completions:
 - minor filetype completions are added for djview, xpdf, mupdf, gv,
   xdvi
 - adduser is copmleted by user and group
 - dlocate and dpkg are completed by packages
 - find: -executable options is added
 - htop: options
 - funced and funcsave are completed by function names
 - ifdown and ifup are copmleted by interfaces
 - kill and killall: options, signals and processes
 - latexmk, ln, nm: options
 - lualatex and xelatex copmletions
 - sudo: -u and -g options
 - wvdial: presets
2011-09-23 12:24:21 +04:00
Jan Kanis
c25c48f763 Merge commit 'refs/merge-requests/13' of git://gitorious.org/fish-shell/fish-shell into merge-requests/13 2011-09-21 16:31:40 +02:00
Jan Kanis
5105d8d87e fixed bug where case-insensitive completion of /path\ with\ spaces/ doesn't reposition the cursor correctly 2011-09-21 15:40:45 +02:00
Mark A. Miller
35af336ff6 Fix an old, old reference to a long-gone fish function for gem.fish 2011-08-13 23:50:54 -05:00
Grissiom
157ca12d4b Merge commit 'refs/merge-requests/12' of git://gitorious.org/fish-shell/fish-shell into merge-requests/12 2011-07-28 10:06:19 +08:00
Adam Cozzette
e9d1a54983 fix: Fish may hang in Linux virtual console
I find that if I have a config.fish consisting of the following two
lines

status --job-control full
. empty.fish

where empty.fish is just an empty file in ~/.config/fish,  Fish will
hang when I attempt to log in on a virtual console (e.g. tty1). If I run
Fish within X11 or with either of those lines commented out,
everything's fine. I think the second line can be any command that cause
Fish to perform a fork().

The fix is pretty simple and just involves replacing getpid() with
getpgrp() in terminal_return_from_job in proc.c. See below for the
detailed explanation. I'm certainly no expert so I would appreciate it
if anyone else can confirm that my fix looks ok.

Here's what causes the bug as far as I can tell:

1. When I login on a virtual console,  /bin/login calls Fish. When Fish
begins executing its process group and the process group controlling the
terminal are both the pid of the /bin/login process.

2. The ". empty.fish" line causes Fish to fork a new process. The new
process creates a new process group and takes control of the terminal
under the name of that process group.

3. When the child process finishes,  the parent prcoess attempts to take
back control of the terminal by setting its controlling process group id
to be its pid.

4. Now there is a mismatch between the process group id of the Fish
shell (= the pid of the /bin/login process) and the process group id
controlling the terminal (= the pid of the Fish shell).
reader_interactive_init detects the mismatch and it thinks that it
doesn't have control of the terminal,  so it hangs as it waits for
control.

My fix just solves the problem in step 3 by having the parent process
correctly reassign control of the terminal to its process group.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2011-07-28 09:50:39 +08:00
Chris Nilsson
c8981c048f Merge commit 'refs/merge-requests/10' of git://gitorious.org/fish-shell/fish-shell into merge-requests/10 2011-07-10 16:32:44 +10:00
Andreas Raster
1ae44c6b3c still didn't work correctly, there were delimiters missing in the conditional as well 2011-06-24 02:45:05 +02:00
Andreas Raster
b2887477e3 last commits fix now also applied in the 'else' clause 2011-06-21 23:17:03 +02:00
Andreas Raster
8e2db29c9a fixed an issue when trying to complete something like 'cd /mnt/windows7/Program\ Files\ \('
fish would always spew a huge error message all over my terminal complaining about
some kind of tokenizer error, this patch fixed that
2011-06-21 17:02:49 +02:00
Shaun Reich
d38de7365a Change git-symbolic-ref to git symbolic-ref.
On my system at least (fedora 15), git-symbolic-ref is an invalid
command. Not sure if it's a BIC change from git itself, a distribution
thing, or a mistake on my end. Either way, no harm in using the
extended version. Now I get git branch status (yay).
2011-06-19 14:14:40 -04:00
Jakukyo Friel
cde6067cae minor changes on user doc 2011-02-20 02:58:11 +08:00
Christopher Nilsson
2583638f4b Merge commit 'refs/merge-requests/8' of git://gitorious.org/fish-shell/fish-shell into merge_request_8 2011-01-11 23:22:27 +11:00
Dylan Smith
11360b018f 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.
2010-12-02 23:55:45 +08:00
Grissiom
bdfc62184d fish_indent: indent "case" with the same level as "swith" 2010-12-02 23:42:48 +08:00
Grissiom
74f06d550a 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.
2010-12-02 23:42:24 +08:00
James Bowlin
46986ad4c2 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 <chaos.proton@gmail.com>
2010-12-02 01:33:56 +08:00
Dylan Smith
6a5d6471c5 mimedb: Search for exact mime type match in search_ini. 2010-12-02 01:19:56 +08:00
Dylan Smith
cf0850edfd 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.
2010-12-02 01:16:29 +08:00
Dylan Smith
fd4ac87382 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.
2010-12-02 01:13:51 +08:00
Dylan Smith
164144f126 default_key_bindings: Added mappings for ctrl-arrow keys.
On debian and ubuntu these control sequences are output while using
gnome-terminal and xterm.
2010-12-02 01:13:04 +08:00
Dylan Smith
f2ad4a2e8e Makefile: test for xsel directory before trying to clean it.
This avoids the users seeing ignored errors for make -C  clean.
2010-12-02 01:12:34 +08:00
Grissiom
df23913bb8 fish_indent: only output fd number when have to
The original patch is own by Dylan. I just did some cleaning and
reformating.
2010-12-01 13:05:10 +08:00
Dylan Smith
4ccf26fbcc 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 <chaos.proton@gmail.com>
2010-11-26 19:00:18 +08:00
Dylan Smith
081e277fe4 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 <chaos.proton@gmail.com>
2010-11-25 19:09:31 +08:00
Christopher Nilsson
dcecab384a Merge commit 'refs/merge-requests/6' of git://gitorious.org/fish-shell/fish-shell into merge_req_6 2010-11-24 22:34:29 +11:00
James Vega
4f9b07e979 Allow fish_greeting to be NULL or an array
Treat fish_greeting as a whole when show up the greeting messages. And
the user may want to set fish_greeting to an null value or an array.
This requires that the variable be quoted when used as an argument for
switch in __fish_config_interactive.

Signed-off-by: James Vega <jamessan@debian.org>
[modified the commit message]
Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-24 00:49:15 +08:00
Grissiom
9b97c55546 add test case for 364d3dbbf8 2010-11-24 00:35:56 +08:00
Dylan Smith
364d3dbbf8 exec: Don't format status returned directly from builtin function
The builtin function returns the raw status, which is not the same as
the integer return by waitpid. Therefore, the WIF macros shouldn't be
used for checking or obtaining the status.

This bug can be seen by executing (eval false). The builtin eval
function returns 1, but proc_format_status misinterprets it as a signal
by checking WIFSIGNALED, so adds 128 to the status to return 129.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-24 00:27:16 +08:00
James Vega
9f3a4d1640 Fix some spelling mistakes
Fix spelling mistakes in various bits of the documentation.

Signed-off-by: James Vega <jamessan@debian.org>
Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-23 23:50:49 +08:00
Dylan Smith
5fca92994f help.fish: Fix the sed expression to find anchors with id or name
Previously the expression only searched for anchors with a name
attribute, but doxygen 1.7.1 is producing anchors with the id attribute
instead. The sed expression allows both cases for compatibility.

I also used single quotes for the sed expression to avoid escaping
double quotes.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-23 23:37:09 +08:00
Grissiom
fefd17fe5e add test case for 6b243fbc 2010-11-23 23:05:21 +08:00
Dylan Smith
6b243fbcd3 eval: (eval false) should return an error status
This also caused (isatty < /dev/null) to return 0 since it uses eval,
and (ls | cat) to output using the classify indicator style since it
uses isatty. This is how I found the bug.

Reviewed-by: Grissiom <chaos.proton@gmail.com>
2010-11-22 19:36:42 +08:00
Dylan Smith
82f8c3834e Makefile: Provide PACKAGE_TARNAME for autoconf default docdir
docdir was previously being set to "${prefix}/share/doc/${PACKAGE_NAME}"
when it wasn't explicitely set on configuration using --docdir. Without
this appearing in the Makefile, some files silently get silently
installed directly into ${prefix}/share/doc instead within a fish
subdirectory.

I also added datarootdir to fix an autoconf warning,  since autoconf
normally would use it for the directory paths (e.g. docdir =
${datarootdir}/doc/${PACKAGE_TARNAME}). The autoconf generated configure
script has a hack to fix this, but states: "FIXME: This hack should be
removed a few years after 2.60."
2010-11-22 19:05:06 +08:00
Grissiom
e0ba91db31 Revert "use is_interactive instead of isatty to test whether we are in interactive mode"
This reverts commit ceba377ab8.
2010-11-22 08:43:21 +08:00
Grissiom
fa148bf59f break long lines 2010-11-22 08:42:57 +08:00
Christopher Nilsson
1b0ce33669 Merged changes from codemonkey and grissiom branches
Conflicts:
	kill.c
	seq.in
2010-11-12 02:07:14 +11:00
David Frascone
0cf2a1eb33 Fixed negative indices in the seq command 2010-11-05 09:34:42 -06:00
David Frascone
8a46a8ecb2 This change allows for customizing of the clipboard buffer, by supplying
a command to accept the "copy".  So, you add your clipboard buffer command
to an environment variable, and custom commands will be used for the copy
program.  Very useful when your OS is not naitively supported by fish.
2010-11-05 09:32:05 -06:00
David Frascone
4f0221bc4f Modify getopt string to force posix compliance. I forgot why I
needed this -- but -- some options were not working right.
2010-11-05 09:29:10 -06:00
David Frascone
ce08bb2ad2 The grep on the commands would sometimes output errors, causing noise and
breaking scripts.
2010-11-05 09:26:26 -06:00
David Frascone
93f797326e Optimized the result of the xsel check, so that it is cached.
It is called very often, and causes a significant performace hit.  The
availability of xsel is not likely to change during the invocation of
the shell.
2010-11-05 09:22:28 -06:00
Grissiom
ceba377ab8 use is_interactive instead of isatty to test whether we are in interactive mode 2010-10-13 04:30:23 +08:00
Grissiom
b9b6e867df check allocated memory when setting SHLVL 2010-10-08 09:38:06 +08:00
Grissiom
f47caefdb9 fix a memory allocation bug in commit 1e27024d75 2010-10-08 09:01:25 +08:00
James Buren
41ae7bccc2 silences some warnings outputted by gcc with -Wall and -Wextra 2010-10-08 08:43:57 +08:00
Grissiom
1e27024d75 accumulate SHLVL env variable at startup 2010-10-08 08:35:22 +08:00
Grissiom
6654fff377 fix null reference when erase TERM env
Way to reproduce:

> set -e TERM
fish: function contains_internal called with null value for argument a.
fish: This is a bug. If you can reproduce it,  please send a bug report
to fish-users@lists.sf.net.
fish: Backtrace:
/home/grissiom/sysroot/bin/fish(show_stackframe+0x1a) [0x43519a]
/home/grissiom/sysroot/bin/fish(contains_internal+0xce) [0x4373ee]
/home/grissiom/sysroot/bin/fish(reader_write_title+0x59) [0x424179]
/home/grissiom/sysroot/bin/fish() [0x4242d5]
/home/grissiom/sysroot/bin/fish(reader_readline+0x54) [0x425974]
/home/grissiom/sysroot/bin/fish(reader_read+0xba) [0x42742a]
/home/grissiom/sysroot/bin/fish(main+0x4be) [0x43b19e]
/lib64/libc.so.6(__libc_start_main+0xfd) [0x7fcbe0dcbb6d]
/home/grissiom/sysroot/bin/fish() [0x408c29]
2010-10-06 20:58:13 +08:00
Grissiom
89d999df72 some optimization on filling prompt_buff 2010-10-06 20:37:30 +08:00
Grissiom
a941d82be3 don't expand variables in no_exec mode
We couldn't know variables values unless execute commands, so disable
variable expansion in no_exec mode.
2010-10-06 11:37:59 +08:00
Grissiom
694cdf5ae1 update .gitignore 2010-10-05 21:14:43 +08:00
Grissiom
2bfe4afea2 add prof target 2010-10-05 02:23:18 +08:00
Grissiom
d559c3fe2e fix bug in build debug targe 2010-10-05 02:22:33 +08:00
Grissiom
27df727ca1 don't parse the options that should be passed to fish scripts
This commit makes fish_parse_opt stop at first non-option argument,
which expected as fish script name and pass the remaining argument to
that script. I also updated the test cases.
2010-10-03 11:46:26 +08:00
Grissiom
8910226d2f only count the last line of promt when caculate prompt width 2010-09-24 19:01:13 +08:00
Grissiom
04f58b1a31 ignore tmp staff in tests/ 2010-09-24 11:34:35 +08:00
Grissiom
1b9dd0c75f Merge remote branch 'origin/otherchirps-dev' 2010-09-19 14:12:30 +08:00
Grissiom
a7af415b6a call original grep in sgrep
functions/grep.fish will set the GREP_OPTIONS, which will ruin sgrep's
effort.
2010-09-19 13:56:30 +08:00
Grissiom
f8a5a59513 Revert "match the whole command for git completion"
This reverts commit d957d23d8f.
Use __fish_git_using_command to test commands and __fish_contains_opt to
test arguments.
2010-09-19 11:04:24 +08:00
Grissiom
ac3dfb3f96 don't complete file names for git checkout 2010-09-19 00:19:44 +08:00
Grissiom
d957d23d8f match the whole command for git completion 2010-09-19 00:17:53 +08:00
Grissiom
d049947801 event_fire( 0 ); => event_fire( NULL ); 2010-09-18 21:30:02 +08:00
Grissiom
21a10c3c74 use $() in Makefile var expansion 2010-09-18 21:29:05 +08:00
Grissiom
04951f8b34 reader_read( 0... => reader_read( STDIN_FILENO 2010-09-18 20:26:54 +08:00
Grissiom
c08bae6aeb configure xsel in configure phase
... and with the same arguments of fish
2010-09-18 14:31:18 +08:00
Grissiom
3aa107c4ae add XSEL_BIN var in configure.ac 2010-09-18 13:49:03 +08:00
Grissiom
e196091714 make clean should clean xsel and make distclean should delete it 2010-09-18 13:41:27 +08:00
Grissiom
d35d65cc40 use variables as xsel target 2010-09-18 13:27:34 +08:00
Grissiom
7f7b30959b don't make xsel in subshell 2010-09-18 13:14:59 +08:00
Grissiom
70322077d2 remove trialing spaces #2 2010-09-18 10:18:26 +08:00
Grissiom
f529b2e057 upgrade xsel to 1.2.0
xsel 1.0 begin to support UFT-8.
2010-09-18 10:14:14 +08:00
Grissiom
c6372a1b3f remove trailing spaces
This is done by `sed -i -e 's/[ \t]*$//' *.[c,h]`, which should not
introduce any functionality change.
2010-09-18 09:51:16 +08:00
Grissiom
41b8db063c add git submodule completion
Merged from http://github.com/weavejester/fish-git
2010-09-17 16:38:26 +08:00
Grissiom
1b16758d7e Fix cd prompt fail on the case that CDPATH have variables 2010-09-17 16:01:44 +08:00
Grissiom
51b5adc306 ignore ~ backup files 2010-09-16 13:32:18 +08:00
Grissiom
56f8993b8c ignore po/*.gmo 2010-09-16 13:31:49 +08:00
Ben Hoskings
8c4d1ca587 Added .gitignore. 2010-09-16 13:30:59 +08:00
Christopher Nilsson
ec8b3593f3 added '-c' option to the functions.txt docs. 2010-09-12 20:29:34 +10:00
Christopher Nilsson
5c9b42e260 'functions --copy': added sanity check on new function name.
Now matches function create behaviour, running the new function name through
wcsfuncname() and parser_keywords_is_reserved(), before allowing the copy.
2010-09-12 13:16:11 +10:00
Christopher Nilsson
7914c92824 replaced the functions '--rename' option with '--copy'.
Copying the function implementation was the main point. Actually removing the original isn't necessary, as that
functionality already exists (functions -e).
2010-09-09 23:48:18 +10:00
Christopher Nilsson
208be0f4d4 Adding '--rename' option to 'functions' builtin.
Aim is to allow an existing function to be renamed, allowing some basic function chaining.

Example:

> function foo
     echo Hello
  end
> foo
Hello
> functions --rename foo bar
> foo
fish: Unknown command 'foo'
> bar
Hello
> functions --rename fish_prompt old_prompt
> function fish_prompt
      printf "{Boo!}%s" (old_prompt)
  end
{Boo!}>

Note in the last case, the new fish_prompt is calling its old definition.
2010-09-08 03:31:05 +10:00
Ben Hoskings
7cfac5bb59 Fix an fprintf() type warning in set_color.c by using "%s". 2010-04-09 16:05:19 -07:00
Ben Hoskings
1bd09bfd40 Fix casting warnings in screen.c / s_update() by casting al_get() twice to convert type and then size, instead of both at once. 2010-04-09 16:05:18 -07:00
Ben Hoskings
517751f2a3 Declare write_loop() in print_help.c to fix warning (it's declared in common.h, but including that file here breaks things badly). 2010-04-09 16:05:18 -07:00
Ben Hoskings
006952c571 Fixed incompatible pointer warning in env_universal_common.c / iconv() call. 2010-04-09 16:05:18 -07:00
Ben Hoskings
7a8b7201a1 Write formatted duration to ENV_DURATION after commands that run for > 1s wall time. 2010-04-09 15:56:32 -07:00
Ben Hoskings
1157e4d7b2 Allow newlines in fish_prompt, by joining prompt_list with newlines instead of nothing in exec_prompt(). 2010-04-09 15:56:15 -07:00
Ben Hoskings
6b8e7b16f6 Reduced timeout in select_try() from 5s to 10ms. 2010-04-09 15:56:09 -07:00
axel
1eb089d722 Bump version number
darcs-hash:20090308144106-ac50b-e64db4a3009f99b3c1d206bba1781775faef671c.gz
2009-03-09 00:41:06 +10:00
axel
e50d0c18b0 Update todo list
darcs-hash:20090308142007-ac50b-22e9cc31212ff9647f75426327cdf5aff2d30f79.gz
2009-03-09 00:20:07 +10:00
axel
810d5f9548 Fix interactive job in background busy wait bug, reported by Randall D. Wald
darcs-hash:20090301021441-ac50b-a9488a9e55f545c3b8bd52aa0fb00b2b967974a8.gz
2009-03-01 12:14:41 +10:00
James Vega
e0c317dfd4 Prevent potential infinite loop
Ignore-this: 24edfe9248e1b667fcf4d8e151dd50f2

darcs-hash:20090224183601-35ec8-5e86d44c77af33376bd80485689d60c761ff17c6.gz
2009-02-25 04:36:01 +10:00
axel
d5320fb9f9 Update copyright info, minor layout changes to section about licenses in fish
darcs-hash:20090222224540-ac50b-69c4f8dd027e4672b8d25f8240c1d5f625135ad1.gz
2009-02-23 08:45:40 +10:00
axel
14c84ffbcb Check return value of a few write calls and retry on EINTR, and fix a few other warnings, mostly by printing error messages before giving up.
darcs-hash:20090222202852-ac50b-b0e79142af5b7a99e55271d4001fa252d9684a1d.gz
2009-02-23 06:28:52 +10:00
axel
f71c6f3f0e Misc documentation updates
darcs-hash:20090222191714-ac50b-fdd090aafd60f71989ef5c63aac9f876dcad93eb.gz
2009-02-23 05:17:14 +10:00
axel
6dbb9e070d Hopefully make iconv detection work on OS X with non-gnu iconv implementation
darcs-hash:20090222191649-ac50b-4f7010fdbf662b71cb7c4c99d2ae6e00c7cccb83.gz
2009-02-23 05:16:49 +10:00
axel
47ae2a05ce Don't make complete builtin complain when used in non-interactive mode, as we can always launch a debug prompt. Who are we to question why?
darcs-hash:20090222162253-ac50b-bb3c9dc1d1fa33548a2ed7b3c7c4d21d527eba47.gz
2009-02-23 02:22:53 +10:00
axel
810262118a Fix read in noninteractive mode problems reported by James Reeves
darcs-hash:20090222162206-ac50b-c293945986f75103120606a64133b59fe82c02a6.gz
2009-02-23 02:22:06 +10:00
axel
f5be301a2f Handle exit status of processes terminated by signals
darcs-hash:20090221164656-ac50b-7bcbf6cb0bb8384560fbf9bf1059480cb4089def.gz
2009-02-22 02:46:56 +10:00
axel
b1357d11b2 Pressing Control-C (or otherwise changeing the command line content through the commandline builtin) should clear the search buffer.
darcs-hash:20090221154420-ac50b-52641fb6dd6e76aebc6244211e07c0861fb3eff0.gz
2009-02-22 01:44:20 +10:00
axel
5fc42fcaff prompt_pwd broken, this fix by James Reeves
darcs-hash:20090221104759-ac50b-35f7a896d3e62cd002605d47c090c7bec992317b.gz
2009-02-21 20:47:59 +10:00
axel
c1cf6a4071 Oops, I broke recursive wildcard completion
darcs-hash:20090221104330-ac50b-ab9d487d3fc77fab32d9c49045d23b3e9124e618.gz
2009-02-21 20:43:30 +10:00
axel
972f3e121e Document rename of save_function to func_save. Pointed out by Ovchinnikov George
darcs-hash:20090218202037-ac50b-0351e8564d3274cd4fb364c07b4a3260f8a45f20.gz
2009-02-19 06:20:37 +10:00
axel
0dd8ae4843 Added faw entry on history editing, written by Beni Cherniavsky
darcs-hash:20090216211940-ac50b-4175fb2ae8ec2f5a67ac3c6a33a48bc5ac35eea2.gz
2009-02-17 07:19:40 +10:00
axel
8a93b6f26d Make xdg-version of open handle multiple files.
darcs-hash:20090216211103-ac50b-f8268e8d50a84457bb49ac3d1e982cba09dbfec6.gz
2009-02-17 07:11:03 +10:00
axel
07717a3570 Add possibility to define greeting function, suggested by Chris Miller
darcs-hash:20090216210450-ac50b-9b4f7c5bf45afaf21d51e46ff8c2b11d171fcbf2.gz
2009-02-17 07:04:50 +10:00
Nick Pilon
79784d3e18 This patch fixes a problem where prompt_pwd was printing the full path twice under OS X and probably BSDs. (Which, needless to say, made for very long prompts) The problem was that (Free?)BSD sed and GNU sed handle ? differently. For BSD sed, ? is not special unless the -E flag is specified. The {0,1} syntax should work the same way in both.
darcs-hash:20080122180340-5b666-21f1cdb835cbfa458a0f3d7344370837db962388.gz
2008-01-23 04:03:40 +10:00
terceiro
c08c313c0a adds completion for Debian's invoke-rc.d command
Ignore-this: f9ff385e3c239cedfbc9850b06822bba

darcs-hash:20090204191757-69c1e-a55c2a720fd784c7be2534feacecd5e2ebdbeecd.gz
2009-02-05 05:17:57 +10:00
terceiro
dfd70057b3 function to put current git branch on the fish prompt
Ignore-this: 841402742571f399e012514315b8e4f0

darcs-hash:20090204190358-69c1e-2ebcf761a4e55bc049ff1d5bba272d722b2d4501.gz
2009-02-05 05:03:58 +10:00
terceiro
07dec5c3ed better git completion
Ignore-this: af7fede5c1ee1d92c89d2887cbe54c0b

darcs-hash:20090204185826-69c1e-f72e06ad575efee258b392afd17255166ac4a260.gz
2009-02-05 04:58:26 +10:00
axel
1ed5decf2c Fix warnings in FATAL_EXIT macro
darcs-hash:20090204224310-ac50b-111db6c8f5b74dad0a309441063d3d7e9bf8f55d.gz
2009-02-05 08:43:10 +10:00
Isaac Dupree
9b95dda6bf fix help for open
darcs-hash:20080605192305-6c1c4-ccf59a87bf7197b5d07a33d7aaeb31638aa0aa52.gz
2008-06-06 05:23:05 +10:00
axel
41015691db Make all fish that use universal variables binaries include iconv
darcs-hash:20090203002620-ac50b-6be533cd1bf7dd043d96547b2c2f3ab4cda30e10.gz
2009-02-03 10:26:20 +10:00
axel
7e1ac2d806 Actually escape the double-star recursive wildcard char when requested. This will make sure the syntax highlighting doesn't try to perform a recursive wildcard expansion when cheching command name existance, which killed performance
darcs-hash:20090202234751-ac50b-55dfd8b52f842826b02a69d6ab51c222108c30e3.gz
2009-02-03 09:47:51 +10:00
axel
35258bf1fb Make proper autoconf test for availability of posix nan function instead of fudging with the NAN macro.
darcs-hash:20090202232049-ac50b-0176955677ff39fdd05eeefa20dca883863c34e6.gz
2009-02-03 09:20:49 +10:00
axel
72025a6a38 Make fish avoid iterating through user list when completing file part of directory starting with tilde. Also add a timeout to the directory iteration, to protect against humongously large user databases.
darcs-hash:20090202224645-ac50b-353047a73e4d6f494f470fe2ea6c4a34b486d302.gz
2009-02-03 08:46:45 +10:00
axel
05341b055b ish's current hostname completion uses ~/.ssh/known_hosts as one of its sources of information, but ~/.ssh/config may also be useful. Gather all of the 'Host' declarations from ~/.ssh/config and filter out the ones with wildcards. Signed-off-by: James Vega <jamessan@debian.org>
darcs-hash:20090202210242-ac50b-cf50070ee33ab6113e32a4d997d464ac4b1faf24.gz
2009-02-03 07:02:42 +10:00
axel
9d7224d756 Add support for completing aliases in ssh. Written by David Bronke.
darcs-hash:20090201231805-ac50b-196d4c81981efe681677fe8ca7f1cc833a4734da.gz
2009-02-02 09:18:05 +10:00
axel
33ec8b45a0 Add effectv completions, written by Stefano Sabatini.
darcs-hash:20090201225558-ac50b-5704829043880d0264e3e3908d324a39857ada16.gz
2009-02-02 08:55:58 +10:00
axel
1dc49a4062 Fix color ls detection for BSD and OS X systems. Patch by Sven Axelsson.
darcs-hash:20090201222410-ac50b-e1e02244ae950c602d3b7e67fe567920c619024b.gz
2009-02-02 08:24:10 +10:00
axel
1123467991 Fix cd function to handle empty variables correctly. Patch by Sven Axelsson.
darcs-hash:20090201222058-ac50b-31a7ee2db9f68729c21ba153e1439cbeabff84ce.gz
2009-02-02 08:20:58 +10:00
axel
4f54da3795 Fix user completion so it can handle comments in the passwd file. Patch by Sven Axelsson.
darcs-hash:20090201221921-ac50b-ef0883afe4dc68b43c1c705d49b6b5505dbf1e73.gz
2009-02-02 08:19:21 +10:00
axel
c8de3d24c8 Add netcat completions, written by James Stanley
darcs-hash:20090201160411-ac50b-43c34e2a73477cde40f15887a810a7b365ec81c4.gz
2009-02-02 02:04:11 +10:00
axel
31439ffb52 Better warning message when trying to exit with jobs running. PAtch and suggestion from Josef Spillner.
darcs-hash:20090201151601-ac50b-64bf24877419a9087f37eda2486232dfdabea9d2.gz
2009-02-02 01:16:01 +10:00
axel
9111b85437 Fixed bug with configure.ac in autotools shipped with F10. This fix comes from James Reeves.
darcs-hash:20090201140928-ac50b-952a8ba0596e3cf4f4a4a94f226fd04ec607075f.gz
2009-02-02 00:09:28 +10:00
axel
c6427c5a47 Add mimedb infinite loop bug fix from James Reeves
darcs-hash:20090201133734-ac50b-96fb4735af616094ea57ba02266188f8a7038a0c.gz
2009-02-01 23:37:34 +10:00
axel
36c3bd4e8d Switch from ARG_MAX to getting value from sysconf, glibc no longer defines the latter. This was reported from Peter Alfredsen Matthew Wesley, among other people.
darcs-hash:20090201132329-ac50b-5b9d54731c2ea2da3868fd492e68628b7684bb76.gz
2009-02-01 23:23:29 +10:00
axel
dad549afd1 Fix slightly wrong LD_FLAG in Makefile
darcs-hash:20090201125628-ac50b-3e68d7165a6c19558c7c8d7189cb75d71b4a9875.gz
2009-02-01 22:56:28 +10:00
Ori Avtalion
e73c2be216 Add missing commas, letters and \c in the documentation
darcs-hash:20080210210053-57fc3-f7e03b3fca9dff8bdc02256dfb78478b68945015.gz
2008-02-11 07:00:53 +10:00
axel
b0d324f1a7 Fix dumb error causing fish not to compile...
darcs-hash:20080204230945-ac50b-a95529cf19c473f62b6104ae138cf8b8abcbd2ec.gz
2008-02-05 09:09:45 +10:00
axel
d7396ac59f Fix bug causing flood of error messages in terminal when trying to highlight an invalid command, reported by Denilson F. de Sa.
darcs-hash:20080204230905-ac50b-0829b69835347e5875656ae735181b724f10de2a.gz
2008-02-05 09:09:05 +10:00
liljencrantz
3f439e9cd3 Add quilt completions, written by Stefano Sabatini.
darcs-hash:20080123000021-75c98-b27ae979720c55ec2219f451c50e87e79fa38cd6.gz
2008-01-23 10:00:21 +10:00
liljencrantz
0b722864c0 Make string handling a bit more solid be making sure sb_printf returns a null terminated string even on failiure.
darcs-hash:20080120022045-75c98-a47aff63ce7278148ccf027d6ee3ff93b35ee350.gz
2008-01-20 12:20:45 +10:00
liljencrantz
75e26f0f94 Add completions for various user and group adding commands. Skip addgroup, since manual page was actually for adduser, most switches weren't applicable and I was too lazy to guess which ones.
darcs-hash:20080120020816-75c98-f937df6cb6789868a1385bfc3eb48f5ddefb3c43.gz
2008-01-20 12:08:16 +10:00
liljencrantz
8cacb33347 Add completions for m4
darcs-hash:20080119150149-75c98-d8e5060ef78c6103d51e453ee4d5265f0981c4af.gz
2008-01-20 01:01:49 +10:00
liljencrantz
bf7d62fd91 Add completions for badblocks
darcs-hash:20080119145849-75c98-657a11bc69fbf625b01f84f1f6638e0d4b767228.gz
2008-01-20 00:58:49 +10:00
liljencrantz
4ac31e637d Add completions for Battle of Wesnoth
darcs-hash:20080119145414-75c98-6d8f856062ea44cf5de56bb014765a65ac26706b.gz
2008-01-20 00:54:14 +10:00
liljencrantz
0ad64ad2e4 Improve documentaion for bind builtin, clarify how to specify key sequences.
darcs-hash:20080119003820-75c98-b1f9360ddab9206a1cdf77b94ce28e9978badb53.gz
2008-01-19 10:38:20 +10:00
liljencrantz
523096e5d8 Add simple git completions by Diggory Hardy
darcs-hash:20080118160327-75c98-33e4e011de409944143aecf4f7e7aa8995687c75.gz
2008-01-19 02:03:27 +10:00
liljencrantz
0de629e009 Fix spelling in docs and add a help page for the funced builtin. These changes where suggested by Emanuele Rusconi.
darcs-hash:20080118155413-75c98-eadff877b3af3c3271b098903f80a45082111424.gz
2008-01-19 01:54:13 +10:00
liljencrantz
1f6fa1208e Search for command-not-found in PATH on startup, since older implementations place it there
darcs-hash:20080115122953-75c98-05ef8cb650a942c59dfa35aa63b25ccd49614dde.gz
2008-01-15 22:29:53 +10:00
liljencrantz
b86856b454 In prompt_pwd, if a directory name starts with a dot, include first two characters. This patch was written by Denilson F. de Sá
darcs-hash:20080116223621-75c98-46f96c9f25d5e32cd10148d35713622e6eac50d7.gz
2008-01-17 08:36:21 +10:00
liljencrantz
6598320534 Remove useless stray argument in function call
darcs-hash:20080116222628-75c98-a307fbeacdd815edcedea05930dc8b4bb064acb3.gz
2008-01-17 08:26:28 +10:00
liljencrantz
0a66dc4a31 Correct completions for the function builtin
darcs-hash:20080116222602-75c98-c1a48b4a04fe71b25c5e004a282341148a95ab6d.gz
2008-01-17 08:26:02 +10:00
liljencrantz
88a2b622df Add more documentation on events
darcs-hash:20080116222531-75c98-ef30dabc492d7883dbb620c40ef95152469057a3.gz
2008-01-17 08:25:31 +10:00
liljencrantz
e10f75483f Fix minor bug, PWD was incorrectly set on startup
darcs-hash:20080116220738-75c98-2b7c886629857540efee8f1cab9da0aa9ed8f76d.gz
2008-01-17 08:07:38 +10:00
liljencrantz
1a66fc4c5d Drop vim feature of only completing text and gzip files
darcs-hash:20080116180249-75c98-2fdff83afcb286c7cc06d3ed66089c9cc02eca20.gz
2008-01-17 04:02:49 +10:00
liljencrantz
905b792de7 Improve code comment
darcs-hash:20080116010601-75c98-fc7e940543424479bf1016cec26af619f177f5fd.gz
2008-01-16 11:06:01 +10:00
liljencrantz
804f5ab334 Add an extra input validation check
darcs-hash:20080116010548-75c98-e6f198bb1eb5a456ce830c42f061428a9c6f755d.gz
2008-01-16 11:05:48 +10:00
liljencrantz
f974c7c416 Improve error messages on failed execve calls a bit more
darcs-hash:20080116010454-75c98-883050bf00f10bdb205724d7d273f10e6f0a1065.gz
2008-01-16 11:04:54 +10:00
liljencrantz
f3b6b74568 Oops. Made a minor but important typo in previous cleanup patch. :-(
darcs-hash:20080115004050-75c98-3f7f733cca054d8685ec5df68d6467057ea5be53.gz
2008-01-15 10:40:50 +10:00
liljencrantz
ab94a397c3 Drop minor typo, add a few code comments
darcs-hash:20080114225828-75c98-f67f17d7f3148b0bcc74ea53536d52da80667e55.gz
2008-01-15 08:58:28 +10:00
liljencrantz
537ab32dd9 Add support for the Ubuntu 'command-no-found' handler, which suggests a package to install in order to get a command.
darcs-hash:20080114223124-75c98-ab1658d54086394cf13f3a6210543c0b790362c4.gz
2008-01-15 08:31:24 +10:00
liljencrantz
a2660cfb76 Handle case insensitive completions of variables better
darcs-hash:20080114010032-75c98-6e570c2b095baeb2ed2ee4d09e32f4e7d6ae47de.gz
2008-01-14 11:00:32 +10:00
liljencrantz
3743a5758b The max size of the string buffer was too small. Push it up a bit.
darcs-hash:20080114005745-75c98-1bcad5c5e81d4257eb7e96e860f8c667f9ba3267.gz
2008-01-14 10:57:45 +10:00
James Vega
e510d10c77 Fixed various spelling errors.
darcs-hash:20080113200151-35ec8-c587f020aec07a5e613068677bd3dd4f5c6189ac.gz
2008-01-14 06:01:51 +10:00
liljencrantz
f5540ff958 Add canse insensitive tilde completion
darcs-hash:20080113193221-75c98-169804fe128001f73eaee6fab28bfb99dca7c93e.gz
2008-01-14 05:32:21 +10:00
liljencrantz
c2b28063e1 Improve Doxygen documentation generation a bit
darcs-hash:20080113164924-75c98-d9762465de42750728ac6cb9364f4739a29ae376.gz
2008-01-14 02:49:24 +10:00
liljencrantz
8d2564291d Make sure fish_indent handles io erros
darcs-hash:20080113164905-75c98-b090ce79fb50a260874951525218cac65a097a6d.gz
2008-01-14 02:49:05 +10:00
liljencrantz
87db9517e9 Add lots of new code comments.
darcs-hash:20080113164747-75c98-9d0cefd27be7aef7ba60772616d9da7e6bb52912.gz
2008-01-14 02:47:47 +10:00
559 changed files with 52603 additions and 36233 deletions

4
.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
.gitattributes export-ignore
.gitignore export-ignore
/build_tools export-ignore

34
.gitignore vendored Normal file
View File

@@ -0,0 +1,34 @@
*.o
*~
Doxyfile.help
Makefile
autom4te.cache/
builtin_scripts.cpp
builtin_scripts.h
command_list.txt
config.h
config.h.in
config.log
config.status
configure
doc.h
doc_src/commands.hdr
doc_src/index.hdr
po/*.gmo
fish
fish.spec
fish_indent
fish_pager
fish_tests
fishd
mimedb
seq
set_color
share/config.fish
share/man/
toc.txt
user_doc/
xsel-1.2.0/
tests/*tmp.*
tests/foo.txt

3
CHANGELOG Normal file
View File

@@ -0,0 +1,3 @@
24-01-2012 Jan Kanis
* Added a changelog file
* removed unescaping if the 'commandline' builtin is called without the -o (tokenise) flag

939
Doxyfile

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,8 @@ ABBREVIATE_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO
@@ -19,7 +19,7 @@ DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 8
ALIASES =
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
@@ -44,7 +44,7 @@ GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = YES
@@ -53,19 +53,19 @@ WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
INPUT =
WARN_LOGFILE =
INPUT =
FILE_PATTERNS = doc.h
RECURSIVE = NO
EXCLUDE =
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
@@ -75,17 +75,17 @@ REFERENCES_RELATION = YES
VERBATIM_HEADERS = YES
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
IGNORE_PREFIX =
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER = user_doc.head.html
HTML_FOOTER =
HTML_STYLESHEET =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
@@ -99,8 +99,8 @@ LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
@@ -109,33 +109,33 @@ GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
PERLMOD_MAKEVAR_PREFIX =
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
TAGFILES =
GENERATE_TAGFILE =
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
@@ -151,8 +151,8 @@ INCLUDED_BY_GRAPH = YES
CALL_GRAPH = YES
GRAPHICAL_HIERARCHY = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 750
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 0

File diff suppressed because it is too large Load Diff

View File

@@ -49,10 +49,15 @@ Then, use following commands to compile fish:
Finally, if you wish to use fish as your default shell, use the
following command:
% chsh -s /usr/local/bin/fish
% chsh -s /usr/local/bin/fish
chsh will prompt you for your password, and change your default shell.
To switch your default shell back, you can run:
% chsh -s /bin/bash
Substitute /bin/bash with /bin/tcsh or /bin/zsh as appropriate.
Local install procedure
=======================

View File

@@ -31,12 +31,14 @@
# hallucinations.
#
# Used by docdir
PACKAGE_TARNAME = @PACKAGE_TARNAME@
#
# Programs
#
CC := @CC@
CXX := @CXX@
INSTALL:=@INSTALL@
@@ -46,23 +48,22 @@ INSTALL:=@INSTALL@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@
bindir = @bindir@
mandir = @mandir@
sysconfdir = @sysconfdir@
docdir = @docdir@
localedir = @localedir@
prefix = @prefix@
optbindirs = @optbindirs@
optbindirs = @optbindirs@
#
# Various flags
#
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
CFLAGS = @CFLAGS@ $(MACROS)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LIBS@ @LDFLAGS@
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
CXXFLAGS = @CXXFLAGS@ $(MACROS) $(EXTRA_CXXFLAGS)
LDFLAGS = @LIBS@ @LDFLAGS@
LDFLAGS_FISH = ${LDFLAGS} @LIBS_FISH@ @LDFLAGS_FISH@
LDFLAGS_FISH_INDENT = ${LDFLAGS} @LIBS_FISH_INDENT@
LDFLAGS_FISH_PAGER = ${LDFLAGS} @LIBS_FISH_PAGER@
@@ -78,11 +79,11 @@ HAVE_GETTEXT=@HAVE_GETTEXT@
#
#Additional .c files used by common.o. These also have a corresponding
#Additional .cpp files used by common.o. These also have a corresponding
#.h file.
#
COMMON_FILES := util.c halloc.c halloc_util.c fallback.c
COMMON_FILES := util.cpp fallback.cpp
#
@@ -93,8 +94,9 @@ FISH_OBJS := function.o builtin.o complete.o env.o exec.o expand.o \
highlight.o history.o kill.o parser.o proc.o reader.o sanity.o \
tokenizer.o wildcard.o wgetopt.o wutil.o input.o output.o intern.o \
env_universal.o env_universal_common.o input_common.o event.o \
signal.o io.o parse_util.o common.o screen.o path.o \
parser_keywords.o
signal.o io.o parse_util.o common.o screen.o path.o autoload.o \
parser_keywords.o iothread.o builtin_scripts.o color.o postfork.o \
builtin_test.o
FISH_INDENT_OBJS := fish_indent.o print_help.o common.o \
parser_keywords.o wutil.o tokenizer.o
@@ -103,8 +105,8 @@ parser_keywords.o wutil.o tokenizer.o
# Additional files used by builtin.o
#
BUILTIN_FILES := builtin_set.c builtin_commandline.c \
builtin_ulimit.c builtin_complete.c builtin_jobs.c
BUILTIN_FILES := builtin_set.cpp builtin_commandline.cpp \
builtin_ulimit.cpp builtin_complete.cpp builtin_jobs.cpp
#
@@ -113,7 +115,7 @@ BUILTIN_FILES := builtin_set.c builtin_commandline.c \
FISH_PAGER_OBJS := fish_pager.o output.o wutil.o \
input_common.o env_universal.o env_universal_common.o common.o \
print_help.o
print_help.o iothread.o color.o
#
@@ -158,7 +160,25 @@ HDR_FILES_SRC := doc_src/index.hdr.in doc_src/commands.hdr.in doc_src/design.hdr
HDR_FILES := $(subst .hdr.in,.hdr,$(HDR_FILES_SRC))
#
# Files containing documentation for external commands.
# Internalized scripts
#
GENERATED_INTERN_SCRIPT_FILES := builtin_scripts.h builtin_scripts.cpp
# Use a pattern rule so that Make knows to only issue one invocation
# per http://www.gnu.org/software/make/manual/make.html#Pattern-Intro
# Internalized scripts are currently disabled.
# For now, we just generate empty arrays.
# To generate them again, you would run this:
# ./internalize_scripts.py share/functions/*.fish share/completions/*.fish
builtin%scripts.h builtin%scripts.cpp: internalize_scripts.py
./internalize_scripts.py
#
# Files containing documentation for external commands.
#
HELP_SRC := $(wildcard doc_src/*.txt)
@@ -188,12 +208,12 @@ DOC_SRC_DIR_FILES := $(HDR_FILES_SRC) $(HELP_SRC)
MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
Makefile.in configure configure.ac config.h.in install-sh \
set_color.c key_reader.c $(MIME_OBJS:.o=.h) \
$(MIME_OBJS:.o=.c) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \
$(COMMON_FILES) $(COMMON_FILES:.c=.h) $(FISH_OBJS:.o=.c) \
set_color.cpp key_reader.cpp $(MIME_OBJS:.o=.h) \
$(MIME_OBJS:.o=.cpp) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \
$(COMMON_FILES) $(COMMON_FILES:.cpp=.h) $(FISH_OBJS:.o=.cpp) \
fish.spec.in INSTALL README user_doc.head.html xsel-0.9.6.tar \
ChangeLog config.sub config.guess fish_tests.c fish.c fish_pager.c \
fishd.c seq.in make_vcs_completions.fish $(FISH_INDENT_OBJS:.o=.c)
ChangeLog config.sub config.guess fish_tests.cpp fish.cpp fish_pager.cpp \
fishd.cpp seq.in make_vcs_completions.fish $(FISH_INDENT_OBJS:.o=.cpp)
#
# The sorting is not meaningful in itself, but it has the side effect
@@ -204,20 +224,6 @@ MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
MAIN_DIR_FILES := $(sort $(MAIN_DIR_FILES_UNSORTED))
#
# Files in ./etc/
#
ETC_DIR_FILES :=etc/config.fish.in
#
# Files in ./share/
#
SHARE_DIR_FILES :=share/config.fish.in
#
# Files in ./tests/
#
@@ -245,7 +251,7 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)
#
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL_BIN@ @SEQ_FALLBACK@
#
@@ -264,12 +270,19 @@ TRANSLATIONS_SRC := $(wildcard po/*.po)
TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
#
# Extra util
#
XSEL := @XSEL@
XSEL_BIN := @XSEL_BIN@
#
# Make everything needed for installing fish
#
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish $(TRANSLATIONS)
@echo fish has now been built.
all: $(PROGRAMS) user_doc share/man $(TRANSLATIONS)
@echo fish has now been built.
@echo Use \'$(MAKE) install\' to install fish.
.PHONY: all
@@ -291,41 +304,40 @@ Makefile: Makefile.in configure
# and should only be used when debuging fish.
#
debug:
$(MAKE) fish CFLAGS="@CFLAGS@ $(MACROS) -O0 -Wno-unused -Werror -g"
.PHONY: debug
prof: EXTRA_CXXFLAGS += -pg
prof: LDFLAGS += -pg
prof: all
.PHONY: prof
#
# User documentation, describing the features of the fish shell.
#
# Depend on the sources (*.hdr.in) and manually make the
# Depend on the sources (*.hdr.in) and manually make the
# intermediate *.hdr and doc.h files if needed
# Allow doxygen to fail, e.g. if it does not exist
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
$(MAKE) doc.h $(HDR_FILES)
doxygen Doxyfile.user
touch user_doc
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC) doc.h $(HDR_FILES)
- doxygen Doxyfile.user && touch user_doc
#
# Source code documentation. Also includes user documentation.
#
doc: *.h *.c doc.h Doxyfile
doxygen;
doc: *.h *.cpp doc.h Doxyfile
doxygen;
#
# PDF version of the source code documentation.
#
doc/refman.pdf: doc
cd doc/latex;
make;
mv refman.pdf ..;
cd ../..;
doc/refman.pdf: doc
cd doc/latex;
make;
mv refman.pdf ..;
cd ../..;
rm -r doc/latex;
@@ -342,11 +354,8 @@ test: $(PROGRAMS) fish_tests
# Build the xsel program, which is maintained in its own tarball
#
xsel-0.9.6:
tar -xf xsel-0.9.6.tar
xsel-0.9.6/xsel: xsel-0.9.6
cd xsel-0.9.6; ./configure && make || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
$(XSEL_BIN):
$(MAKE) -C $(XSEL) || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
#
@@ -362,7 +371,7 @@ doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in
echo >>command_list.tmp; \
echo >>command_list.tmp; \
echo "Back to <a href='index.html#toc-commands'>index</a>". >>command_list.tmp; \
done
done
mv command_list.tmp command_list.txt
cat $@.in | awk '{if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@
@@ -400,19 +409,19 @@ doc.h: $(HDR_FILES)
#
%.doxygen:%.txt
echo "/** \page " `basename $*` >$@;
cat $*.txt >>$@;
echo "/** \page " `basename $*` >$@;
cat $*.txt >>$@;
echo "*/" >>$@
%: %.in
%: %.in
sed <$@.in >$@ \
-e "s,@sysconfdir\@,$(sysconfdir),g" \
-e "s,@datadir\@,$(datadir),g" \
-e "s,@docdir\@,$(docdir),g" \
-e "s|@configure_input\@|$@, generated from $@.in by the Makefile. DO NOT MANUALLY EDIT THIS FILE!|g" \
-e "s,@prefix\@,$(prefix),g" \
-e "s,@optbindirs\@,$(optbindirs),g"
#-e "s,@\@,$(),"
-e "s,@optbindirs\@,$(optbindirs),g"
#-e "s,@\@,$(),"
#
@@ -443,10 +452,10 @@ doc.h: $(HDR_FILES)
# Create a template translation object
#
messages.pot: *.c *.h etc/*.in share/*.in share/completions/*.fish share/functions/*.fish seq
messages.pot: *.cpp *.h share/completions/*.fish share/functions/*.fish seq
if test $(HAVE_GETTEXT) = 1;then \
xgettext -k_ -kN_ *.c *.h -o messages.pot; \
if xgettext -j -k_ -kN_ -k--description -LShell etc/*.in share/*.in share/completions/*.fish share/functions/*.fish seq -o messages.pot; then true; else \
xgettext -k_ -kN_ *.cpp *.h -o messages.pot; \
if xgettext -j -k_ -kN_ -k--description -LShell share/completions/*.fish share/functions/*.fish seq -o messages.pot; then true; else \
echo "Your xgettext version is too old to build the messages.pot file"\
rm messages.pot\
false;\
@@ -477,8 +486,8 @@ common.o: $(COMMON_FILES)
# (__fish_print_help)
# ||
# \/
# formated text
# with escape
# formated text
# with escape
# sequences
#
#
@@ -496,13 +505,15 @@ share/man: $(HELP_SRC)
cat $$i >>$$FILE; \
echo "*/" >>$$FILE; \
done
doxygen Doxyfile.help
for i in $(HELP_SRC); do \
CMD_NAME=`basename $$i .txt`; \
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <help_doc/man/man1/$$CMD_NAME.1 >share/man/$$CMD_NAME.1; \
done
if command -v doxygen; then \
doxygen Doxyfile.help ; \
for i in $(HELP_SRC); do \
CMD_NAME=`basename $$i .txt`; \
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <help_doc/man/man1/$$CMD_NAME.1 >share/man/$$CMD_NAME.1; \
done \
fi
rm doc_src/*.doxygen # Clean up intermediate files in doc_src/
rm -r help_doc # Clean up intermediate help_doc tree
rm -rf help_doc # Clean up intermediate help_doc tree
#
# The build rules for installing/uninstalling fish
@@ -562,29 +573,54 @@ install: all install-sh check-uninstall install-force
#
# Force installation, even in presense of incompatible previous
# version. This may fail.
# These 'true' lines are to prevent installs from failing for (e.g.) missing man pages.
#
install-force: all install-translations
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
for i in $(PROGRAMS); do\
$(INSTALL) -m 755 $$i $(DESTDIR)$(bindir) ; \
true ;\
done;
$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/fish
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man/man1
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts
$(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/
$(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/
for i in $(COMPLETIONS_DIR_FILES); do \
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/completions/; \
true; \
done;
for i in $(FUNCTIONS_DIR_FILES); do \
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/functions/; \
true; \
done;
for i in share/man/*.1; do \
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/man1/; \
true; \
done;
for i in share/tools/*.py; do\
$(INSTALL) -m 755 $$i $(DESTDIR)$(datadir)/fish/tools/; \
true; \
done;
for i in share/tools/web_config/*; do\
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \
true; \
done;
for i in share/tools/web_config/sample_prompts/*.fish; do\
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts/; \
true; \
done;
for i in share/tools/web_config/*.py; do\
$(INSTALL) -m 755 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \
true; \
done;
$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
for i in user_doc/html/* ChangeLog; do \
if test -f $$i; then \
@@ -594,14 +630,19 @@ install-force: all install-translations
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
for i in $(MANUALS); do \
$(INSTALL) -m 644 $$i $(DESTDIR)$(mandir)/man1/; \
true; \
done;
@echo fish is now installed on your system.
@echo fish is now installed on your system.
@echo To run fish, type \'fish\' in your terminal.
@echo
@echo To use fish as your login shell:
@echo \* add the line \'$(DESTDIR)$(bindir)/fish\' to the file \'/etc/shells\'.
@echo \* use the command \'chsh -s $(DESTDIR)$(bindir)/fish\'.
@echo
@echo To set your colors, run \'fish_config\'
@echo To scan your man pages for completions, run \'fish_update_completions\'
@echo To autocomplete command suggestions press Ctrl + F or right arrow key.
@echo
@echo Have fun!
.PHONY: install-force
@@ -615,16 +656,15 @@ uninstall: uninstall-translations
rm -f $(DESTDIR)$(bindir)/$$i; \
done;
-rm -f $(DESTDIR)$(bindir)/xsel
-rm -f $(DESTDIR)$(sysconfdir)/fish/config.fish
-rmdir $(DESTDIR)$(sysconfdir)/fish
-rm -rf $(DESTDIR)$(sysconfdir)/fish
-if test -d $(DESTDIR)$(datadir)/fish; then \
rm -r $(DESTDIR)$(datadir)/fish; \
fi
-if test -d $(DESTDIR)$(docdir); then \
rm -r $(DESTDIR)$(docdir);\
rm -rf $(DESTDIR)$(docdir);\
fi
-for i in $(MANUALS); do \
rm -f $(DESTDIR)$(mandir)/man1/`basename $$i`*; \
rm -rf $(DESTDIR)$(mandir)/man1/`basename $$i`*; \
done;
.PHONY: uninstall
@@ -652,7 +692,7 @@ uninstall-legacy: uninstall
-rmdir $(DESTDIR)$(sysconfdir)/fish.d/completions
-rmdir $(DESTDIR)$(sysconfdir)/fish.d
-rm $(DESTDIR)$(sysconfdir)/fish
@echo The previous fish installation has been removed.
@echo The previous fish installation has been removed.
.PHONY: uninstall-legacy
install-translations: $(TRANSLATIONS)
@@ -665,7 +705,7 @@ install-translations: $(TRANSLATIONS)
fi;
.PHONY: install-translations
uninstall-translations:
uninstall-translations:
if test $(HAVE_GETTEXT) = 1; then \
for i in $(TRANSLATIONS_SRC); do \
rm -f $(DESTDIR)$(datadir)/locale/*/LC_MESSAGES/fish.mo; \
@@ -682,8 +722,8 @@ uninstall-translations:
# Build the fish program.
#
fish: $(FISH_OBJS) fish.o
$(CC) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
fish: $(FISH_OBJS) fish.o
$(CXX) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
#
@@ -691,15 +731,15 @@ fish: $(FISH_OBJS) fish.o
#
fish_pager: $(FISH_PAGER_OBJS)
$(CC) $(FISH_PAGER_OBJS) $(LDFLAGS_FISH_PAGER) -o $@
$(CXX) $(FISH_PAGER_OBJS) $(LDFLAGS_FISH_PAGER) -o $@
#
# Build the fishd program.
#
fishd: $(FISHD_OBJS)
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
fishd: $(FISHD_OBJS)
$(CXX) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
#
@@ -707,7 +747,7 @@ fishd: $(FISHD_OBJS)
#
fish_tests: $(FISH_TESTS_OBJS)
$(CC) $(FISH_TESTS_OBJS) $(LDFLAGS_FISH) -o $@
$(CXX) $(FISH_TESTS_OBJS) $(LDFLAGS_FISH) -o $@
#
@@ -717,23 +757,23 @@ fish_tests: $(FISH_TESTS_OBJS)
#
mimedb: $(MIME_OBJS)
$(CC) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@
$(CXX) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@
#
# Build the set_color program
#
set_color: set_color.o print_help.o common.o
$(CC) set_color.o print_help.o common.o wutil.o $(LDFLAGS_SET_COLOR) -o $@
set_color: set_color.o print_help.o common.o color.o wutil.o
$(CXX) set_color.o print_help.o common.o wutil.o color.o $(LDFLAGS_SET_COLOR) -o $@
#
# Test program for the tokenizer library
#
tokenizer_test: tokenizer.c tokenizer.h wutil.o common.o
$(CC) $(CFLAGS) tokenizer.c wutil.o common.o -D TOKENIZER_TEST $(LDFLAGS) -o $@
tokenizer_test: tokenizer.cpp tokenizer.h wutil.o common.o
$(CXX) $(CXXFLAGS) tokenizer.cpp wutil.o common.o -D TOKENIZER_TEST $(LDFLAGS) -o $@
#
@@ -741,67 +781,30 @@ tokenizer_test: tokenizer.c tokenizer.h wutil.o common.o
#
fish_indent: $(FISH_INDENT_OBJS)
$(CC) $(FISH_INDENT_OBJS) $(LDFLAGS_FISH_INDENT) -o $@
$(CXX) $(FISH_INDENT_OBJS) $(LDFLAGS_FISH_INDENT) -o $@
#
# Neat little program to show output from terminal
#
key_reader: key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o
$(CC) key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o $(LDFLAGS) -o $@
key_reader: key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o iothread.o
$(CXX) key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o iothread.o $(LDFLAGS_FISH) -o $@
#
# Update dependencies
#
depend:
makedepend -fMakefile.in -Y *.c
makedepend -fMakefile.in -Y *.cpp
./config.status
.PHONY: depend
#
# Copy all the source files into a new directory and use tar to create
# an archive from it. Simplest way I could think of to make an archive
# witout backups, autogenerated files, etc.
#
# Uses install instead of mkdir so build won't fail if the directory
# exists
#
fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FILES) $(TEST_DIR_FILES) $(SHARE_DIR_FILES) $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES) ChangeLog user_doc share/man
rm -rf fish-@PACKAGE_VERSION@
$(INSTALL) -d fish-@PACKAGE_VERSION@
$(INSTALL) -d fish-@PACKAGE_VERSION@/doc_src
$(INSTALL) -d fish-@PACKAGE_VERSION@/user_doc
$(INSTALL) -d fish-@PACKAGE_VERSION@/etc
$(INSTALL) -d fish-@PACKAGE_VERSION@/share
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/completions
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/functions
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/man
$(INSTALL) -d fish-@PACKAGE_VERSION@/tests
$(INSTALL) -d fish-@PACKAGE_VERSION@/po
cp -f $(DOC_SRC_DIR_FILES) fish-@PACKAGE_VERSION@/doc_src
cp -f $(MAIN_DIR_FILES) fish-@PACKAGE_VERSION@/
cp -f $(ETC_DIR_FILES) fish-@PACKAGE_VERSION@/etc/
cp -f $(SHARE_DIR_FILES) fish-@PACKAGE_VERSION@/share/
cp -f $(COMPLETIONS_DIR_FILES) fish-@PACKAGE_VERSION@/share/completions/
cp -f $(FUNCTIONS_DIR_FILES) fish-@PACKAGE_VERSION@/share/functions/
cp -f $(TESTS_DIR_FILES) fish-@PACKAGE_VERSION@/tests/
cp -f $(TRANSLATIONS_SRC) fish-@PACKAGE_VERSION@/po/
cp -f share/man/*.1 fish-@PACKAGE_VERSION@/share/man/
cp -rf user_doc fish-@PACKAGE_VERSION@/
tar -c fish-@PACKAGE_VERSION@ >fish-@PACKAGE_VERSION@.tar
rm -rf fish-@PACKAGE_VERSION@
#
# Just an alias for fish-@PACKAGE_VERSION@.tar
# Dependencies that makedepend misses
#
tar: fish-@PACKAGE_VERSION@.tar
.PHONY: tar
autoload.cpp function.cpp: $(GENERATED_INTERN_SCRIPT_FILES)
#
# Make compressed tar archives
@@ -817,7 +820,7 @@ dist: fish-@PACKAGE_VERSION@.tar.bz2
.PHONY: dist
#
# Build the RPM spec file.
# Build the RPM spec file.
#
fish.spec: fish.spec.in
@@ -854,9 +857,9 @@ rpm: fish-@PACKAGE_VERSION@.tar.bz2 fish.spec
#
distclean: clean
rm -f fish.spec Doxyfile.help
rm -f etc/config.fish seq share/config.fish
rm -f fish.spec Doxyfile.help
rm -f config.status config.log config.h Makefile
rm -rf $(XSEL)
.PHONY: distclean
@@ -865,139 +868,155 @@ distclean: clean
# are created by the configure script.
#
# Don't delete the docs unless we have Doxygen installed
# We provide pre-built docs in the tarball, and if they get
# deleted we won't be able to regenerate them
clean:
rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.c doc_src/*.o doc_src/commands.hdr
rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.cpp doc_src/*.o doc_src/commands.hdr
rm -f $(GENERATED_INTERN_SCRIPT_FILES)
rm -f tests/tmp.err tests/tmp.out tests/tmp.status tests/foo.txt
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
rm -f share/config.fish etc/config.fish doc_src/index.hdr doc_src/commands.hdr
rm -f fish-@PACKAGE_VERSION@.tar
rm -f fish-@PACKAGE_VERSION@.tar.gz
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
rm -f command_list.txt toc.txt
rm -f doc_src/index.hdr doc_src/commands.hdr
rm -f fish-@PACKAGE_VERSION@.tar
rm -f fish-@PACKAGE_VERSION@.tar.gz
rm -f fish-@PACKAGE_VERSION@.tar.bz2
rm -rf doc;
if command -v doxygen; then \
rm -rf doc user_doc share/man; \
fi
rm -rf fish-@PACKAGE_VERSION@
rm -rf xsel-0.9.6/
rm -f $(TRANSLATIONS)
test ! -d "$(XSEL)" || make -C $(XSEL) clean
.PHONY: clean
# DO NOT DELETE THIS LINE -- make depend depends on it.
builtin.o: config.h fallback.h util.h wutil.h builtin.h io.h function.h
builtin.o: complete.h proc.h parser.h event.h reader.h env.h common.h
builtin.o: wgetopt.h sanity.h tokenizer.h wildcard.h input_common.h input.h
builtin.o: intern.h signal.h exec.h highlight.h halloc.h halloc_util.h
builtin.o: parse_util.h parser_keywords.h expand.h path.h builtin_set.c
builtin.o: builtin_commandline.c builtin_complete.c builtin_ulimit.c
builtin.o: builtin_jobs.c
autoload.o: config.h autoload.h common.h util.h lru.h wutil.h signal.h env.h
autoload.o: builtin_scripts.h exec.h proc.h io.h
builtin.o: config.h signal.h fallback.h util.h wutil.h builtin.h io.h
builtin.o: common.h function.h event.h complete.h proc.h parser.h reader.h
builtin.o: env.h wgetopt.h sanity.h tokenizer.h wildcard.h input_common.h
builtin.o: input.h intern.h exec.h highlight.h screen.h color.h parse_util.h
builtin.o: autoload.h lru.h parser_keywords.h expand.h path.h builtin_set.cpp
builtin.o: builtin_commandline.cpp builtin_complete.cpp builtin_ulimit.cpp
builtin.o: builtin_jobs.cpp
builtin_commandline.o: config.h signal.h fallback.h util.h wutil.h builtin.h
builtin_commandline.o: io.h common.h wgetopt.h reader.h proc.h parser.h
builtin_commandline.o: event.h tokenizer.h input_common.h input.h
builtin_commandline.o: parse_util.h
builtin_commandline.o: event.h function.h tokenizer.h input_common.h input.h
builtin_commandline.o: parse_util.h autoload.h lru.h
builtin_complete.o: config.h signal.h fallback.h util.h wutil.h builtin.h
builtin_complete.o: io.h common.h complete.h wgetopt.h parser.h proc.h
builtin_complete.o: event.h reader.h
builtin_jobs.o: config.h fallback.h util.h wutil.h builtin.h io.h proc.h
builtin_jobs.o: parser.h event.h common.h wgetopt.h
builtin_complete.o: event.h function.h reader.h
builtin_jobs.o: config.h fallback.h signal.h util.h wutil.h builtin.h io.h
builtin_jobs.o: common.h proc.h parser.h event.h function.h wgetopt.h
builtin_scripts.o: builtin_scripts.h
builtin_set.o: config.h signal.h fallback.h util.h wutil.h builtin.h io.h
builtin_set.o: env.h expand.h common.h wgetopt.h proc.h parser.h event.h
builtin_ulimit.o: config.h fallback.h util.h builtin.h io.h common.h
builtin_set.o: common.h env.h expand.h wgetopt.h proc.h parser.h event.h
builtin_set.o: function.h
builtin_ulimit.o: config.h fallback.h signal.h util.h builtin.h io.h common.h
builtin_ulimit.o: wgetopt.h
common.o: config.h fallback.h util.h wutil.h common.h expand.h proc.h io.h
common.o: wildcard.h parser.h event.h util.c halloc.c halloc.h halloc_util.c
common.o: fallback.c
complete.o: config.h signal.h fallback.h util.h tokenizer.h wildcard.h proc.h
complete.o: io.h parser.h event.h function.h complete.h builtin.h env.h
complete.o: exec.h expand.h common.h reader.h history.h intern.h parse_util.h
complete.o: parser_keywords.h halloc.h halloc_util.h wutil.h path.h
color.o: color.h config.h common.h util.h
common.o: config.h fallback.h signal.h util.h wutil.h common.h expand.h
common.o: proc.h io.h wildcard.h parser.h event.h function.h complete.h
common.o: util.cpp fallback.cpp
complete.o: config.h signal.h fallback.h util.h tokenizer.h wildcard.h
complete.o: common.h proc.h io.h parser.h event.h function.h complete.h
complete.o: builtin.h env.h exec.h expand.h reader.h history.h intern.h
complete.o: parse_util.h autoload.h lru.h parser_keywords.h wutil.h path.h
complete.o: builtin_scripts.h
env.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h env.h
env.o: sanity.h expand.h history.h reader.h parser.h event.h env_universal.h
env.o: env_universal_common.h input_common.h path.h halloc.h halloc_util.h
env.o: sanity.h expand.h history.h reader.h parser.h event.h function.h
env.o: env_universal.h env_universal_common.h input_common.h path.h
env.o: complete.h
env_universal.o: config.h signal.h fallback.h util.h common.h wutil.h
env_universal.o: env_universal_common.h env_universal.h
env_universal_common.o: config.h signal.h fallback.h util.h common.h wutil.h
env_universal_common.o: env_universal_common.h
event.o: config.h signal.h fallback.h util.h wutil.h function.h proc.h io.h
event.o: parser.h event.h common.h halloc_util.h
event.o: config.h signal.h fallback.h util.h wutil.h function.h common.h
event.o: event.h proc.h io.h parser.h
exec.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
exec.o: exec.h parser.h event.h builtin.h function.h env.h wildcard.h
exec.o: sanity.h expand.h halloc.h halloc_util.h parse_util.h
exec.o: exec.h parser.h event.h function.h builtin.h env.h wildcard.h
exec.o: sanity.h expand.h parse_util.h autoload.h lru.h
expand.o: config.h signal.h fallback.h util.h common.h wutil.h env.h proc.h
expand.o: io.h parser.h event.h expand.h wildcard.h exec.h tokenizer.h
expand.o: complete.h parse_util.h halloc.h halloc_util.h
fallback.o: config.h fallback.h util.h
expand.o: io.h parser.h event.h function.h expand.h wildcard.h exec.h
expand.o: tokenizer.h complete.h parse_util.h autoload.h lru.h
fallback.o: config.h fallback.h signal.h util.h
fish.o: config.h signal.h fallback.h util.h common.h reader.h io.h builtin.h
fish.o: function.h complete.h wutil.h env.h sanity.h proc.h parser.h event.h
fish.o: expand.h intern.h exec.h output.h halloc.h halloc_util.h history.h
fish.o: path.h
fish_indent.o: config.h fallback.h util.h common.h wutil.h halloc.h
fish_indent.o: halloc_util.h tokenizer.h print_help.h parser_keywords.h
fish.o: function.h event.h complete.h wutil.h env.h sanity.h proc.h parser.h
fish.o: expand.h intern.h exec.h output.h screen.h color.h history.h path.h
fish_indent.o: config.h fallback.h signal.h util.h common.h wutil.h
fish_indent.o: tokenizer.h print_help.h parser_keywords.h
fish_pager.o: config.h signal.h fallback.h util.h wutil.h common.h complete.h
fish_pager.o: output.h input_common.h env_universal.h env_universal_common.h
fish_pager.o: halloc.h halloc_util.h print_help.h
fish_pager.o: output.h screen.h color.h input_common.h env_universal.h
fish_pager.o: env_universal_common.h print_help.h
fish_tests.o: config.h signal.h fallback.h util.h common.h proc.h io.h
fish_tests.o: reader.h builtin.h function.h complete.h wutil.h env.h expand.h
fish_tests.o: parser.h event.h tokenizer.h output.h exec.h path.h halloc.h
fish_tests.o: halloc_util.h
fish_tests.o: reader.h builtin.h function.h event.h autoload.h lru.h
fish_tests.o: complete.h wutil.h env.h expand.h parser.h tokenizer.h output.h
fish_tests.o: screen.h color.h exec.h path.h history.h
fishd.o: config.h signal.h fallback.h util.h common.h wutil.h
fishd.o: env_universal_common.h halloc.h halloc_util.h path.h print_help.h
function.o: config.h signal.h wutil.h fallback.h util.h function.h proc.h
function.o: io.h parser.h event.h common.h intern.h reader.h parse_util.h
function.o: parser_keywords.h env.h expand.h halloc.h halloc_util.h
halloc.o: config.h fallback.h util.h common.h halloc.h
halloc_util.o: config.h fallback.h util.h common.h halloc.h
highlight.o: config.h signal.h fallback.h util.h wutil.h highlight.h
highlight.o: tokenizer.h proc.h io.h parser.h event.h parse_util.h
highlight.o: parser_keywords.h builtin.h function.h env.h expand.h sanity.h
highlight.o: common.h complete.h output.h halloc.h halloc_util.h wildcard.h
highlight.o: path.h
history.o: config.h fallback.h util.h wutil.h history.h common.h halloc.h
history.o: halloc_util.h intern.h path.h signal.h
input.o: config.h signal.h fallback.h util.h wutil.h reader.h io.h proc.h
input.o: common.h sanity.h input_common.h input.h parser.h event.h env.h
input.o: expand.h output.h intern.h halloc.h halloc_util.h
input_common.o: config.h fallback.h util.h common.h wutil.h input_common.h
input_common.o: env_universal.h env_universal_common.h
intern.o: config.h fallback.h util.h wutil.h common.h intern.h
io.o: config.h fallback.h util.h wutil.h exec.h proc.h io.h common.h halloc.h
key_reader.o: config.h fallback.h input_common.h
fishd.o: env_universal_common.h path.h print_help.h
function.o: config.h signal.h wutil.h fallback.h util.h function.h common.h
function.o: event.h proc.h io.h parser.h intern.h reader.h parse_util.h
function.o: autoload.h lru.h parser_keywords.h env.h expand.h
function.o: builtin_scripts.h
highlight.o: config.h signal.h fallback.h util.h wutil.h highlight.h env.h
highlight.o: common.h screen.h color.h tokenizer.h proc.h io.h parser.h
highlight.o: event.h function.h parse_util.h autoload.h lru.h
highlight.o: parser_keywords.h builtin.h expand.h sanity.h complete.h
highlight.o: output.h wildcard.h path.h
history.o: config.h fallback.h signal.h util.h sanity.h wutil.h history.h
history.o: common.h intern.h path.h autoload.h lru.h
input.o: config.h signal.h fallback.h util.h wutil.h reader.h io.h common.h
input.o: proc.h sanity.h input_common.h input.h parser.h event.h function.h
input.o: env.h expand.h output.h screen.h color.h intern.h
input_common.o: config.h fallback.h signal.h util.h common.h wutil.h
input_common.o: input_common.h env_universal.h env_universal_common.h
input_common.o: iothread.h
intern.o: config.h fallback.h signal.h util.h wutil.h common.h intern.h
io.o: config.h fallback.h signal.h util.h wutil.h exec.h proc.h io.h common.h
iothread.o: iothread.h signal.h
key_reader.o: config.h fallback.h signal.h input_common.h
kill.o: config.h signal.h fallback.h util.h wutil.h kill.h proc.h io.h
kill.o: sanity.h common.h env.h exec.h halloc.h path.h
mimedb.o: config.h xdgmime.h fallback.h util.h print_help.h
kill.o: common.h sanity.h env.h exec.h path.h
mimedb.o: config.h xdgmime.h fallback.h signal.h util.h print_help.h
output.o: config.h signal.h fallback.h util.h wutil.h expand.h common.h
output.o: output.h halloc_util.h highlight.h
parse_util.o: config.h fallback.h util.h wutil.h common.h tokenizer.h
parse_util.o: parse_util.h expand.h intern.h exec.h proc.h io.h env.h
parse_util.o: signal.h wildcard.h halloc_util.h
output.o: output.h screen.h color.h highlight.h env.h
parse_util.o: config.h fallback.h signal.h util.h wutil.h common.h
parse_util.o: tokenizer.h parse_util.h autoload.h lru.h expand.h intern.h
parse_util.o: exec.h proc.h io.h env.h wildcard.h
parser.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
parser.o: parser.h event.h parser_keywords.h tokenizer.h exec.h wildcard.h
parser.o: function.h builtin.h env.h expand.h reader.h sanity.h
parser.o: parser.h event.h function.h parser_keywords.h tokenizer.h exec.h
parser.o: wildcard.h builtin.h env.h expand.h reader.h sanity.h
parser.o: env_universal.h env_universal_common.h intern.h parse_util.h
parser.o: halloc.h halloc_util.h path.h
parser_keywords.o: config.h fallback.h common.h util.h parser_keywords.h
path.o: config.h fallback.h util.h common.h env.h wutil.h halloc.h
path.o: halloc_util.h path.h expand.h
parser.o: autoload.h lru.h path.h complete.h
parser_keywords.o: config.h fallback.h signal.h common.h util.h
parser_keywords.o: parser_keywords.h
path.o: config.h fallback.h signal.h util.h common.h env.h wutil.h path.h
path.o: expand.h
print_help.o: print_help.h
proc.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h
proc.o: reader.h sanity.h env.h parser.h event.h halloc.h halloc_util.h
proc.o: output.h
reader.o: config.h signal.h fallback.h util.h wutil.h highlight.h reader.h
reader.o: io.h proc.h parser.h event.h complete.h history.h common.h sanity.h
reader.o: env.h exec.h expand.h tokenizer.h kill.h input_common.h input.h
reader.o: function.h output.h screen.h halloc.h halloc_util.h parse_util.h
proc.o: reader.h sanity.h env.h parser.h event.h function.h output.h screen.h
proc.o: color.h
reader.o: config.h signal.h fallback.h util.h wutil.h highlight.h env.h
reader.o: common.h screen.h color.h reader.h io.h proc.h parser.h event.h
reader.o: function.h complete.h history.h sanity.h exec.h expand.h
reader.o: tokenizer.h kill.h input_common.h input.h output.h iothread.h
reader.o: intern.h parse_util.h autoload.h lru.h
sanity.o: config.h signal.h fallback.h util.h common.h sanity.h proc.h io.h
sanity.o: history.h reader.h kill.h wutil.h
screen.o: config.h fallback.h common.h util.h wutil.h output.h highlight.h
screen.o: screen.h env.h
set_color.o: config.h fallback.h print_help.h
screen.o: config.h fallback.h signal.h common.h util.h wutil.h output.h
screen.o: screen.h color.h highlight.h env.h
set_color.o: config.h fallback.h signal.h print_help.h
signal.o: config.h signal.h common.h util.h fallback.h wutil.h event.h
signal.o: reader.h io.h proc.h
tokenizer.o: config.h fallback.h util.h wutil.h tokenizer.h common.h
util.o: config.h fallback.h util.h common.h wutil.h
wgetopt.o: config.h wgetopt.h wutil.h fallback.h
wildcard.o: config.h fallback.h util.h wutil.h complete.h common.h wildcard.h
wildcard.o: reader.h io.h expand.h exec.h proc.h halloc_util.h
wutil.o: config.h fallback.h util.h common.h wutil.h halloc.h halloc_util.h
tokenizer.o: config.h fallback.h signal.h util.h wutil.h tokenizer.h common.h
util.o: config.h fallback.h signal.h util.h common.h wutil.h
wgetopt.o: config.h wgetopt.h wutil.h fallback.h signal.h
wildcard.o: config.h fallback.h signal.h util.h wutil.h complete.h common.h
wildcard.o: wildcard.h reader.h io.h expand.h exec.h proc.h
wutil.o: config.h fallback.h signal.h util.h common.h wutil.h
xdgmime.o: xdgmime.h xdgmimeint.h xdgmimeglob.h xdgmimemagic.h xdgmimealias.h
xdgmime.o: xdgmimeparent.h
xdgmimealias.o: xdgmimealias.h xdgmime.h xdgmimeint.h

15
README
View File

@@ -1,15 +0,0 @@
How to find documentation for fish
==================================
The fish documentation is distributed in an intermediate format. To
view it, you have to type:
% make user_doc
Which will create the directory user_doc, containing html
documentation for fish. If you build and install fish, the
documentation will be available through the 'help' builtin.
After installation, you can start fish by typing fish in the
terminal. After fish has started, try using the help command for more
information.

39
README.md Normal file
View File

@@ -0,0 +1,39 @@
[fish](http://ridiculousfish.com/shell/) - the friendly interactive shell
================================================
fish is a smart and user-friendly command line shell for OS X, Linux, and the rest of the family. fish includes features like syntax highlighting, autosuggest-as-you-type, and fancy tab completions that just work, with no configuration required.
For more on fish's design philosophy, see the [design document](http://ridiculousfish.com/shell/user_doc/html/design.html).
## Quick Start
fish generally works like other shells, like bash or zsh. A few important differences are documented at <http://ridiculousfish.com/shell/faq.html>
Detailed user documentation is available by running `help` within fish, and also at <http://ridiculousfish.com/shell/user_doc/html/>
## Building
fish can be built using autotools or Xcode.
### Autotools Build
autoconf
./configure [--without-xsel]
make [gmake on BSD]
sudo make install
### Xcode Development Build
* Build the `base` target in Xcode
* Run the fish executable, for example, in `DerivedData/FishsFish/Build/Products/Debug/base/bin/fish`
### Xcode Build and Install
mkdir /tmp/fish_build
xcodebuild install -target install_tree DSTROOT=/tmp/fish_build
sudo ditto /tmp/fish_build/ /
## Contact Us
Questions, comments, rants and raves can be posted to the official fish mailing list at <https://lists.sourceforge.net/lists/listinfo/fish-users>
Found a bug? Have an awesome idea? Please open an issue on this github page.

344
autoload.cpp Normal file
View File

@@ -0,0 +1,344 @@
/** \file autoload.cpp
The classes responsible for autoloading functions and completions.
*/
#include "config.h"
#include "autoload.h"
#include "wutil.h"
#include "common.h"
#include "signal.h"
#include "env.h"
#include "builtin_scripts.h"
#include "exec.h"
#include <assert.h>
#include <algorithm>
/* The time before we'll recheck an autoloaded file */
static const int kAutoloadStalenessInterval = 15;
file_access_attempt_t access_file(const wcstring &path, int mode) {
//printf("Touch %ls\n", path.c_str());
file_access_attempt_t result = {0};
struct stat statbuf;
if (wstat(path, &statbuf)) {
result.error = errno;
} else {
result.mod_time = statbuf.st_mtime;
if (waccess(path, mode)) {
result.error = errno;
} else {
result.accessible = true;
}
}
// Note that we record the last checked time after the call, on the assumption that in a slow filesystem, the lag comes before the kernel check, not after.
result.stale = false;
result.last_checked = time(NULL);
return result;
}
autoload_t::autoload_t(const wcstring &env_var_name_var, const builtin_script_t * const scripts, size_t script_count) :
lock(),
env_var_name(env_var_name_var),
builtin_scripts(scripts),
builtin_script_count(script_count),
last_path(),
is_loading_set()
{
pthread_mutex_init(&lock, NULL);
}
autoload_t::~autoload_t() {
pthread_mutex_destroy(&lock);
}
void autoload_t::node_was_evicted(autoload_function_t *node) {
// This should only ever happen on the main thread
ASSERT_IS_MAIN_THREAD();
// Tell ourselves that the command was removed if it was loaded
if (! node->is_loaded)
this->command_removed(node->key);
delete node;
}
int autoload_t::unload( const wcstring &cmd )
{
return this->evict_node(cmd);
}
int autoload_t::load( const wcstring &cmd, bool reload )
{
int res;
CHECK_BLOCK( 0 );
ASSERT_IS_MAIN_THREAD();
env_var_t path_var = env_get_string( env_var_name );
/*
Do we know where to look?
*/
if( path_var.empty() )
return 0;
/* Check if the lookup path has changed. If so, drop all loaded files. path_var may only be inspected on the main thread. */
if( path_var != this->last_path )
{
this->last_path = path_var;
scoped_lock locker(lock);
this->evict_all_nodes();
}
/** Warn and fail on infinite recursion. It's OK to do this because this function is only called on the main thread. */
if (this->is_loading(cmd))
{
debug( 0,
_( L"Could not autoload item '%ls', it is already being autoloaded. "
L"This is a circular dependency in the autoloading scripts, please remove it."),
cmd.c_str() );
return 1;
}
/* Mark that we're loading this */
is_loading_set.insert(cmd);
/* Get the list of paths from which we will try to load */
std::vector<wcstring> path_list;
tokenize_variable_array( path_var, path_list );
/* Try loading it */
res = this->locate_file_and_maybe_load_it( cmd, true, reload, path_list );
/* Clean up */
bool erased = !! is_loading_set.erase(cmd);
assert(erased);
return res;
}
bool autoload_t::can_load( const wcstring &cmd, const env_vars_snapshot_t &vars )
{
const env_var_t path_var = vars.get(env_var_name);
if (path_var.missing_or_empty())
return false;
std::vector<wcstring> path_list;
tokenize_variable_array( path_var, path_list );
return this->locate_file_and_maybe_load_it( cmd, false, false, path_list );
}
static bool script_name_precedes_script_name(const builtin_script_t &script1, const builtin_script_t &script2)
{
return wcscmp(script1.name, script2.name) < 0;
}
void autoload_t::unload_all(void) {
scoped_lock locker(lock);
this->evict_all_nodes();
}
/** Check whether the given command is loaded. */
bool autoload_t::has_tried_loading( const wcstring &cmd )
{
scoped_lock locker(lock);
autoload_function_t * func = this->get_node(cmd);
return func != NULL;
}
static bool is_stale(const autoload_function_t *func) {
/** Return whether this function is stale. Internalized functions can never be stale. */
return ! func->is_internalized && time(NULL) - func->access.last_checked > kAutoloadStalenessInterval;
}
autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcstring &cmd, bool allow_eviction)
{
ASSERT_IS_LOCKED(lock);
autoload_function_t *func = this->get_node(cmd);
if (! func) {
func = new autoload_function_t(cmd);
if (allow_eviction) {
this->add_node(func);
} else {
this->add_node_without_eviction(func);
}
}
return func;
}
/**
This internal helper function does all the real work. By using two
functions, the internal function can return on various places in
the code, and the caller can take care of various cleanup work.
cmd: the command name ('grep')
really_load: whether to actually parse it as a function, or just check it it exists
reload: whether to reload it if it's already loaded
path_list: the set of paths to check
Result: if really_load is true, returns whether the function was loaded. Otherwise returns whether the function existed.
*/
bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list )
{
/* Note that we are NOT locked in this function! */
size_t i;
bool reloaded = 0;
/* Try using a cached function. If we really want the function to be loaded, require that it be really loaded. If we're not reloading, allow stale functions. */
{
bool allow_stale_functions = ! reload;
/* Take a lock */
scoped_lock locker(lock);
/* Get the function */
autoload_function_t * func = this->get_node(cmd);
/* Determine if we can use this cached function */
bool use_cached;
if (! func) {
/* Can't use a function that doesn't exist */
use_cached = false;
} else if (really_load && ! func->is_placeholder && ! func->is_loaded) {
/* Can't use an unloaded function */
use_cached = false;
} else if ( ! allow_stale_functions && is_stale(func)) {
/* Can't use a stale function */
use_cached = false;
} else {
/* I guess we can use it */
use_cached = true;
}
/* If we can use this function, return whether we were able to access it */
if (use_cached) {
return func->is_internalized || func->access.accessible;
}
}
/* The source of the script will end up here */
wcstring script_source;
bool has_script_source = false;
/* Whether we found an accessible file */
bool found_file = false;
/* Look for built-in scripts via a binary search */
const builtin_script_t *matching_builtin_script = NULL;
if (builtin_script_count > 0)
{
const builtin_script_t test_script = {cmd.c_str(), NULL};
const builtin_script_t *array_end = builtin_scripts + builtin_script_count;
const builtin_script_t *found = std::lower_bound(builtin_scripts, array_end, test_script, script_name_precedes_script_name);
if (found != array_end && ! wcscmp(found->name, test_script.name))
{
/* We found it */
matching_builtin_script = found;
}
}
if (matching_builtin_script) {
has_script_source = true;
script_source = str2wcstring(matching_builtin_script->def);
/* Make a node representing this function */
scoped_lock locker(lock);
autoload_function_t *func = this->get_autoloaded_function_with_creation(cmd, really_load);
/* This function is internalized */
func->is_internalized = true;
/* It's a fiction to say the script is loaded at this point, but we're definitely going to load it down below. */
if (really_load) func->is_loaded = true;
}
if (! has_script_source)
{
/* Iterate over path searching for suitable completion files */
for( i=0; i<path_list.size(); i++ )
{
wcstring next = path_list.at(i);
wcstring path = next + L"/" + cmd + L".fish";
const file_access_attempt_t access = access_file(path, R_OK);
if (access.accessible) {
/* Found it! */
found_file = true;
/* Now we're actually going to take the lock. */
scoped_lock locker(lock);
autoload_function_t *func = this->get_node(cmd);
/* Generate the source if we need to load it */
bool need_to_load_function = really_load && (func == NULL || func->access.mod_time != access.mod_time || ! func->is_loaded);
if (need_to_load_function) {
/* Generate the script source */
wcstring esc = escape_string(path, 1);
script_source = L". " + esc;
has_script_source = true;
/* Remove any loaded command because we are going to reload it. Note that this will deadlock if command_removed calls back into us. */
if (func && func->is_loaded) {
command_removed(cmd);
func->is_placeholder = false;
}
/* Mark that we're reloading it */
reloaded = true;
}
/* Create the function if we haven't yet. This does not load it. Do not trigger eviction unless we are actually loading, because we don't want to evict off of the main thread. */
if (! func) {
func = get_autoloaded_function_with_creation(cmd, really_load);
}
/* It's a fiction to say the script is loaded at this point, but we're definitely going to load it down below. */
if (need_to_load_function) func->is_loaded = true;
/* Unconditionally record our access time */
func->access = access;
break;
}
}
/*
If no file or builtin script was found we insert a placeholder function.
Later we only research if the current time is at least five seconds later.
This way, the files won't be searched over and over again.
*/
if( ! found_file && ! has_script_source )
{
scoped_lock locker(lock);
/* Generate a placeholder */
autoload_function_t *func = this->get_node(cmd);
if (! func) {
func = new autoload_function_t(cmd);
func->is_placeholder = true;
if (really_load) {
this->add_node(func);
} else {
this->add_node_without_eviction(func);
}
}
func->access.last_checked = time(NULL);
}
}
/* If we have a script, either built-in or a file source, then run it */
if (really_load && has_script_source)
{
if( exec_subshell( script_source) == -1 )
{
/*
Do nothing on failiure
*/
}
}
if (really_load) {
return reloaded;
} else {
return found_file || has_script_source;
}
}

129
autoload.h Normal file
View File

@@ -0,0 +1,129 @@
/** \file autoload.h
The classes responsible for autoloading functions and completions.
*/
#ifndef FISH_AUTOLOAD_H
#define FISH_AUTOLOAD_H
#include <wchar.h>
#include <map>
#include <set>
#include <list>
#include "common.h"
#include "lru.h"
/** A struct responsible for recording an attempt to access a file. */
struct file_access_attempt_t {
time_t mod_time; /** The modification time of the file */
time_t last_checked; /** When we last checked the file */
bool accessible; /** Whether we believe we could access this file */
bool stale; /** Whether the access attempt is stale */
int error; /** If we could not access the file, the error code */
};
file_access_attempt_t access_file(const wcstring &path, int mode);
struct autoload_function_t : public lru_node_t
{
autoload_function_t(const wcstring &key) : lru_node_t(key), access(), is_loaded(false), is_placeholder(false), is_internalized(false) { }
file_access_attempt_t access; /** The last access attempt */
bool is_loaded; /** Whether we have actually loaded this function */
bool is_placeholder; /** Whether we are a placeholder that stands in for "no such function". If this is true, then is_loaded must be false. */
bool is_internalized; /** Whether this function came from a builtin "internalized" script */
};
struct builtin_script_t;
class env_vars_snapshot_t;
/**
A class that represents a path from which we can autoload, and the autoloaded contents.
*/
class autoload_t : private lru_cache_t<autoload_function_t> {
private:
/** Lock for thread safety */
pthread_mutex_t lock;
/** The environment variable name */
const wcstring env_var_name;
/** Builtin script array */
const struct builtin_script_t *const builtin_scripts;
/** Builtin script count */
const size_t builtin_script_count;
/** The path from which we most recently autoloaded */
wcstring last_path;
/**
A table containing all the files that are currently being
loaded. This is here to help prevent recursion.
*/
std::set<wcstring> is_loading_set;
bool is_loading(const wcstring &name) const {
return is_loading_set.find(name) != is_loading_set.end();
}
void remove_all_functions(void) {
this->evict_all_nodes();
}
bool locate_file_and_maybe_load_it( const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list );
virtual void node_was_evicted(autoload_function_t *node);
autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd, bool allow_eviction);
protected:
/** Overridable callback for when a command is removed */
virtual void command_removed(const wcstring &cmd) { }
public:
/** Create an autoload_t for the given environment variable name */
autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts, size_t script_count );
/** Destructor */
virtual ~autoload_t();
/**
Autoload the specified file, if it exists in the specified path. Do
not load it multiple times unless it's timestamp changes or
parse_util_unload is called.
Autoloading one file may unload another.
\param cmd the filename to search for. The suffix '.fish' is always added to this name
\param on_unload a callback function to run if a suitable file is found, which has not already been run. unload will also be called for old files which are unloaded.
\param reload wheter to recheck file timestamps on already loaded files
*/
int load( const wcstring &cmd, bool reload );
/** Check whether we have tried loading the given command. Does not do any I/O. */
bool has_tried_loading( const wcstring &cmd );
/**
Tell the autoloader that the specified file, in the specified path,
is no longer loaded.
\param cmd the filename to search for. The suffix '.fish' is always added to this name
\param on_unload a callback function which will be called before (re)loading a file, may be used to unload the previous file.
\return non-zero if the file was removed, zero if the file had not yet been loaded
*/
int unload( const wcstring &cmd );
/**
Unloads all files.
*/
void unload_all( );
/** Check whether the given command could be loaded, but do not load it. */
bool can_load( const wcstring &cmd, const env_vars_snapshot_t &vars );
};
#endif

View File

@@ -0,0 +1,3 @@
This is the_ridiculous'fish s delightful fork of, fish friendly interactive shell. For more information, visit http://ridiculousfish.com/shell/ .
This installer will install fish, but will not modify your /etc/shells file or your default shell. I trust you know how to do that yourself if you care to!

View File

@@ -0,0 +1 @@
<pkg-contents spec="1.12"/>

View File

@@ -0,0 +1 @@
<pkgref spec="1.12" uuid="6A7E1ED5-E40E-4ACE-959B-B9D77555AD39"><config><identifier>com.ridiculousfish.fish-shell.fishShell.fish_pkg.pkg</identifier><version>1.0</version><description></description><post-install type="none"/><requireAuthorization/><installFrom>/private/tmp/fish_pkg</installFrom><installTo>/</installTo><flags><followSymbolicLinks/></flags><packageStore type="internal"></packageStore><mod>parent</mod><mod>installTo</mod></config></pkgref>

View File

@@ -0,0 +1,40 @@
<pkmkdoc spec="1.12"><properties><title>fish shell</title><organization>com.ridiculousfish.fish-shell</organization><userSees ui="easy"/><min-target os="3"/><domain anywhere="true"/></properties><distribution><versions min-spec="1.000000"/><scripts></scripts></distribution><contents><choice title="fish_pkg" id="fish shell" starts_selected="true" starts_enabled="true" starts_hidden="false"><pkgref id="com.ridiculousfish.fish-shell.fishShell.fish_pkg.pkg"/></choice></contents><resources bg-scale="proportional" bg-align="bottomleft"><locale lang="en"><resource mod="true" type="background">/Users/peter/Desktop/Untitled.pdf</resource><resource mime-type="text/rtf" kind="embedded" type="welcome"><![CDATA[{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf470
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\f0\fs30 \cf0 This installs ridiculous_fish's fork of fish, a command line shell for Mac OS X, Linux, and the rest of the family. For more information on fish, visit {\field{\*\fldinst{HYPERLINK "http://ridiculousfish.com/shell/"}}{\fldrslt http://ridiculousfish.com/shell/}}\
\
The path to fish will be added to /etc/shells, but your default shell will not be modified. \
\
This release is beta r2.\
}]]></resource><resource mime-type="text/rtf" kind="embedded" type="conclusion"><![CDATA[{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf470
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;}
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\f0\fs26 \cf0 Run
\f1 fish
\f0 at the command line to start it up! Some useful commands:\
\
Interactively set your colors from a web page:\
\
\f1 fish_config
\f0 \
\
Update man-page completions:\
\
\f1 fish_update_completions
\f0 \
\
Make fish your default shell:\
\
\f1 chsh -s /usr/local/bin/fish\
\f0 \
\
Enjoy!\
}]]></resource></locale></resources><flags/><item type="file">01fish.xml</item><mod>properties.title</mod><mod>description</mod></pkmkdoc>

18
build_tools/make_deb.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
# Terminate on error
set -e
sudo rm -Rf /tmp/fishfish
mkdir /tmp/fishfish
git archive --format=tar fish_fish | tar -x -C /tmp/fishfish
mkdir /tmp/fishfish/doc-pak
cp README INSTALL CHANGELOG release_notes.html /tmp/fishfish/doc-pak/
cp build_tools/description-pak /tmp/fishfish/
cd /tmp/fishfish
autoconf
./configure
make -j 3
sudo checkinstall --default --pakdir ~/fish_built/ --pkgversion 0.9 make install
mv ~/fish_built/fishfish_0.9-1_i386.deb ~/fish_built/fishfish_0.9_i386.deb

31
build_tools/make_pkg.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/sh -x
make distclean
rm -rf /tmp/fish_pkg
mkdir -p /tmp/fish_pkg/
# Make sure what we build can run on SnowLeopard
export OSX_SDK="/Developer/SDKs/MacOSX10.6.sdk"
export MACOSX_DEPLOYMENT_TARGET="10.6"
export CC="clang -isysroot $OSX_SDK -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
export CCX="clang++ -isysroot $OSX_SDK -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
export CFLAGS="$CFLAGS -isysroot $OSX_SDK -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
export CXXFLAGS="$CXXFLAGS -isysroot $OSX_SDK -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
export LDFLAGS="$LDFLAGS -isysroot $OSX_SDK -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
autoconf
./configure --without-xsel
# Actually build it now
if make -j 4 DESTDIR=/tmp/fish_pkg install
then
echo "Root written to /tmp/fish_pkg/"
if /Developer/usr/bin/packagemaker --doc ./build_tools/fish_shell.pmdoc --out ~/fish_built/fishfish.pkg
then
echo "Package written to ~/fish_built/fishfish.pkg"
else
echo "Package could not be written"
fi
else
echo "Root could not be written"
fi

46
build_tools/make_tarball.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
# Script to generate a tarball
# We use git to output a tree. But we also want to build the user documentation
# and put that in the tarball, so that nobody needs to have doxygen installed
# to build it.
# Exit on error
set -e
# We wil generate a tarball with a prefix "fish"
# git can do that automatically for us via git-archive
# but to get the documentation in, we need to make a symlink called "fish"
# and tar from that, so that the documentation gets the right prefix
# Get the current directory, which we'll use for symlinks
wd="$PWD"
# The name of the prefix, which is the directory that you get when you untar
prefix="fish"
# The path where we will output the tar file
path=~/fish_built/fish-2.0.tar
# Clean up stuff we've written before
rm -f "$path" "$path".gz
# git starts the archive
git archive --format=tar --prefix="$prefix"/ master > "$path"
# tarball out the documentation
make user_doc
make share/man
cd /tmp
rm -f "$prefix"
ln -s "$wd" "$prefix"
tar --append --file="$path" "$prefix"/user_doc/html
tar --append --file="$path" "$prefix"/share/man
rm -f "$prefix"
# gzip it
gzip "$path"
# Output what we did, and the sha1 hash
echo "Tarball written to $path".gz
openssl sha1 "$path".gz

View File

@@ -0,0 +1,53 @@
#!/bin/sh -e
# Modified from Debian's add-shell to work on OS X
if test $# -eq 0
then
echo usage: $0 shellname [shellname ...]
exit 1
fi
scriptname=`basename "$0"`
if [[ $UID -ne 0 ]]; then
echo "${scriptname} must be run as root"
exit 1
fi
file=/etc/shells
# I want this to be GUARANTEED to be on the same filesystem as $file
tmpfile=${file}.tmp
set -o noclobber
trap "rm -f $tmpfile" EXIT
if ! cat $file > $tmpfile
then
cat 1>&2 <<EOF
Either another instance of $0 is running, or it was previously interrupted.
Please examine ${tmpfile} to see if it should be moved onto ${file}.
EOF
exit 1
fi
# Append a newline if it doesn't exist
if [ "$(tail -c1 "$tmpfile"; echo x)" != $'\nx' ]; then
echo "" >> "$tmpfile"
fi
for i
do
if ! grep -q "^${i}$" "$tmpfile"
then
echo $i >> "$tmpfile"
fi
done
chmod 0644 $tmpfile
chown root:wheel $tmpfile
mv $tmpfile $file
trap "" EXIT
exit 0

View File

@@ -0,0 +1,3 @@
#!/bin/sh -x
./add-shell /usr/local/bin/fish > /tmp/fish_postinstall_output.log

3890
builtin.c

File diff suppressed because it is too large Load Diff

4105
builtin.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,9 @@
#include "util.h"
#include "io.h"
#include "common.h"
class parser_t;
enum
{
@@ -70,6 +73,10 @@ enum
#define BUILTIN_FOR_ERR_NAME _( L"%ls: '%ls' is not a valid variable name\n" )
/** Error messages for 'else if' */
#define BUILTIN_ELSEIF_ERR_COUNT _( L"%ls: can only take 'if' and then another command as an argument\n")
#define BUILTIN_ELSEIF_ERR_ARGUMENT _( L"%ls: any second argument must be 'if'\n")
/**
Error message when too many arguments are supplied to a builtin
*/
@@ -86,15 +93,13 @@ enum
#define BUILTIN_END_BLOCK_UNKNOWN _( L"%ls: Unknown block type '%ls'\n" )
#define BUILTIN_ERR_NOT_NUMBER _( L"%ls: Argument '%ls' is not a number\n" )
/**
Stringbuffer used to represent standard output
*/
extern string_buffer_t *sb_out;
/**
Stringbuffer used to represent standard error
*/
extern string_buffer_t *sb_err;
/** Get the string used to represent stdout and stderr */
const wcstring &get_stdout_buffer();
const wcstring &get_stderr_buffer();
/** Output an error */
void builtin_show_error(const wcstring &err);
/**
Kludge. Tells builtins if output is to screen
@@ -120,40 +125,43 @@ void builtin_destroy();
/**
Is there a builtin command with the given name?
*/
int builtin_exists( wchar_t *cmd );
int builtin_exists( const wcstring &cmd );
/**
Execute a builtin command
\param parser The parser being used
\param argv Array containing the command and parameters
of the builtin. The list is terminated by a
null pointer. This syntax resembles the syntax
for exec.
\param io the io redirections to perform on this builtin.
\return the exit status of the builtin command
*/
int builtin_run( wchar_t **argv, io_data_t *io );
int builtin_run( parser_t &parser, const wchar_t * const *argv, const io_chain_t &io );
/** Returns a list of all builtin names */
wcstring_list_t builtin_get_names(void);
/** Insert all builtin names into list. */
void builtin_get_names(std::vector<completion_t> &list);
/**
Insert all builtin names into l. These are not copies of the strings and should not be freed after use.
Pushes a new set of input/output to the stack. The new stdin is supplied, a new set of output strings is created.
*/
void builtin_get_names( array_list_t *list );
void builtin_push_io( parser_t &parser, int stdin_fd );
/**
Pushes a new set of input/output to the stack. The new stdin is supplied, a new set of output string_buffer_ts is created.
Pops a set of input/output from the stack. The output strings are destroued, but the input file is not closed.
*/
void builtin_push_io( int stdin_fd );
/**
Pops a set of input/output from the stack. The output string_buffer_ts are destroued, but the input file is not closed.
*/
void builtin_pop_io();
void builtin_pop_io(parser_t &parser);
/**
Return a one-line description of the specified builtin
Return a one-line description of the specified builtin.
*/
const wchar_t *builtin_get_desc( const wchar_t *b );
wcstring builtin_get_desc( const wcstring &b );
/**
@@ -166,10 +174,9 @@ const wchar_t *builtin_complete_get_temporary_buffer();
/**
Run the __fish_print_help function to obtain the help information
for the specified command. The resulting string will be valid until
the next time this function is called, and must never be free'd manually.
for the specified command.
*/
wchar_t *builtin_help_get( const wchar_t *cmd );
wcstring builtin_help_get( parser_t &parser, const wchar_t *cmd );
#endif

View File

@@ -52,13 +52,21 @@ enum
}
;
static wchar_t *current_buffer=0;
static int current_cursor_pos = -1;
/**
Pointer to what the commandline builtin considers to be the current
contents of the command line buffer.
*/
static const wchar_t *current_buffer=0;
/**
What the commandline builtin considers to be the current cursor
position.
*/
static size_t current_cursor_pos = (size_t)(-1);
/**
Returns the current commandline buffer.
*/
static wchar_t *get_buffer()
static const wchar_t *get_buffer()
{
return current_buffer;
}
@@ -66,7 +74,7 @@ static wchar_t *get_buffer()
/**
Returns the position of the cursor
*/
static int get_cursor_pos()
static size_t get_cursor_pos()
{
return current_cursor_pos;
}
@@ -82,46 +90,44 @@ static int get_cursor_pos()
*/
static void replace_part( const wchar_t *begin,
const wchar_t *end,
wchar_t *insert,
const wchar_t *insert,
int append_mode )
{
const wchar_t *buff = get_buffer();
string_buffer_t out;
int out_pos=get_cursor_pos();
sb_init( &out );
size_t out_pos = get_cursor_pos();
wcstring out;
sb_append_substring( &out, buff, begin-buff );
out.append(buff, begin - buff);
switch( append_mode)
{
case REPLACE_MODE:
{
sb_append( &out, insert );
out.append(insert);
out_pos = wcslen( insert ) + (begin-buff);
break;
}
case APPEND_MODE:
{
sb_append_substring( &out, begin, end-begin );
sb_append( &out, insert );
out.append( begin, end-begin );
out.append( insert );
break;
}
case INSERT_MODE:
{
int cursor = get_cursor_pos() -(begin-buff);
sb_append_substring( &out, begin, cursor );
sb_append( &out, insert );
sb_append_substring( &out, begin+cursor, end-begin-cursor );
long cursor = get_cursor_pos() -(begin-buff);
out.append( begin, cursor );
out.append( insert );
out.append( begin+cursor, end-begin-cursor );
out_pos += wcslen( insert );
break;
}
}
sb_append( &out, end );
reader_set_buffer( (wchar_t *)out.buff, out_pos );
sb_destroy( &out );
out.append( end );
reader_set_buffer( out, out_pos );
}
/**
@@ -138,9 +144,9 @@ static void write_part( const wchar_t *begin,
int tokenize )
{
tokenizer tok;
string_buffer_t out;
wcstring out;
wchar_t *buff;
int pos;
size_t pos;
pos = get_cursor_pos()-(begin-get_buffer());
@@ -148,7 +154,7 @@ static void write_part( const wchar_t *begin,
{
buff = wcsndup( begin, end-begin );
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
sb_init( &out );
out.clear();
for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
tok_has_next( &tok );
@@ -162,41 +168,30 @@ static void write_part( const wchar_t *begin,
{
case TOK_STRING:
{
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
sb_append( &out, tmp, L"\n", (void *)0 );
free( tmp );
out.append(escape_string(tok_last( &tok ), UNESCAPE_INCOMPLETE));
out.push_back(L'\n');
break;
}
}
}
sb_append( sb_out,
(wchar_t *)out.buff );
stdout_buffer.append(out);
free( buff );
tok_destroy( &tok );
sb_destroy( &out );
}
else
{
wchar_t *buff, *esc;
if( cut_at_cursor )
{
end = begin+pos;
}
buff = wcsndup( begin, end-begin );
esc = unescape( buff, UNESCAPE_INCOMPLETE );
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
sb_append( sb_out, esc );
sb_append( sb_out, L"\n" );
free( esc );
free( buff );
stdout_buffer.append(begin, end - begin);
stdout_buffer.append(L"\n");
}
}
@@ -206,7 +201,7 @@ static void write_part( const wchar_t *begin,
The commandline builtin. It is used for specifying a new value for
the commandline.
*/
static int builtin_commandline( wchar_t **argv )
static int builtin_commandline( parser_t &parser, wchar_t **argv )
{
int buffer_part=0;
@@ -222,7 +217,7 @@ static int builtin_commandline( wchar_t **argv )
int cursor_mode = 0;
int line_mode = 0;
int search_mode = 0;
wchar_t *begin, *end;
const wchar_t *begin, *end;
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
if( current_buffer )
@@ -247,11 +242,9 @@ static int builtin_commandline( wchar_t **argv )
return 1;
}
sb_append( sb_err,
argv[0],
L": Can not set commandline in non-interactive mode\n",
(void *)0 );
builtin_print_help( argv[0], sb_err );
stderr_buffer.append(argv[0]);
stderr_buffer.append(L": Can not set commandline in non-interactive mode\n");
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
@@ -259,7 +252,7 @@ static int builtin_commandline( wchar_t **argv )
while( 1 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -343,11 +336,11 @@ static int builtin_commandline( wchar_t **argv )
case 0:
if(long_options[opt_index].flag != 0)
break;
sb_printf( sb_err,
append_format( stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
@@ -410,11 +403,11 @@ static int builtin_commandline( wchar_t **argv )
break;
case 'h':
builtin_print_help( argv[0], sb_out );
builtin_print_help( parser, argv[0], stdout_buffer );
return 0;
case L'?':
builtin_unknown_option( argv[0], argv[woptind-1] );
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
return 1;
}
}
@@ -428,22 +421,22 @@ static int builtin_commandline( wchar_t **argv )
*/
if( buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode )
{
sb_printf(sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
if( argc == woptind )
{
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_MISSING,
argv[0] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
for( i=woptind; i<argc; i++ )
@@ -460,11 +453,11 @@ static int builtin_commandline( wchar_t **argv )
}
else
{
sb_printf( sb_err,
append_format(stderr_buffer,
_(L"%ls: Unknown input function '%ls'\n"),
argv[0],
argv[i] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
}
@@ -478,45 +471,45 @@ static int builtin_commandline( wchar_t **argv )
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
{
sb_append( sb_err,
append_format(stderr_buffer,
argv[0],
L": Too many arguments\n",
(void *)0 );
builtin_print_help( argv[0], sb_err );
NULL );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
{
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
if( (tokenize || cut_at_cursor) && (argc-woptind) )
{
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_COMBO2,
argv[0],
L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
if( append_mode && !(argc-woptind) )
{
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_COMBO2,
argv[0],
L"insertion mode switches can not be used when not in insertion mode" );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
@@ -538,27 +531,27 @@ static int builtin_commandline( wchar_t **argv )
if( argc-woptind )
{
wchar_t *endptr;
int new_pos;
long new_pos;
errno = 0;
new_pos = wcstol( argv[woptind], &endptr, 10 );
if( *endptr || errno )
{
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_NOT_NUMBER,
argv[0],
argv[woptind] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
}
current_buffer = reader_get_buffer();
new_pos = maxi( 0, mini( new_pos, wcslen( current_buffer ) ) );
reader_set_buffer( current_buffer, new_pos );
new_pos = maxi( 0L, mini( new_pos, (long)wcslen( current_buffer ) ) );
reader_set_buffer( current_buffer, (size_t)new_pos );
return 0;
}
else
{
sb_printf( sb_out, L"%d\n", reader_get_cursor_pos() );
append_format(stdout_buffer, L"%lu\n", (unsigned long)reader_get_cursor_pos() );
return 0;
}
@@ -566,9 +559,9 @@ static int builtin_commandline( wchar_t **argv )
if( line_mode )
{
int pos = reader_get_cursor_pos();
wchar_t *buff = reader_get_buffer();
sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
size_t pos = reader_get_cursor_pos();
const wchar_t *buff = reader_get_buffer();
append_format(stdout_buffer, L"%lu\n", (unsigned long)parse_util_lineno( buff, pos ) );
return 0;
}
@@ -634,21 +627,16 @@ static int builtin_commandline( wchar_t **argv )
default:
{
string_buffer_t sb;
wcstring sb = argv[woptind];
int i;
sb_init( &sb );
sb_append( &sb, argv[woptind] );
for( i=woptind+1; i<argc; i++ )
{
sb_append( &sb, L"\n" );
sb_append( &sb, argv[i] );
sb.push_back(L'\n');
sb.append(argv[i]);
}
replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
sb_destroy( &sb );
replace_part( begin, end, sb.c_str(), append_mode );
break;
}

View File

@@ -26,9 +26,9 @@ Functions used for implementing the complete builtin.
/**
Internal storage for the builtin_get_temporary_buffer() function.
Internal storage for the builtin_complete_get_temporary_buffer() function.
*/
const static wchar_t *temporary_buffer;
static const wchar_t *temporary_buffer;
/*
builtin_complete_* are a set of rather silly looping functions that
@@ -45,15 +45,15 @@ const static wchar_t *temporary_buffer;
static void builtin_complete_add2( const wchar_t *cmd,
int cmd_type,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt,
const wcstring_list_t &gnu_opt,
const wcstring_list_t &old_opt,
int result_mode,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc,
int flags )
{
int i;
size_t i;
const wchar_t *s;
for( s=short_opt; *s; s++ )
@@ -70,12 +70,12 @@ static void builtin_complete_add2( const wchar_t *cmd,
flags );
}
for( i=0; i<al_get_count( gnu_opt ); i++ )
for( i=0; i<gnu_opt.size(); i++ )
{
complete_add( cmd,
cmd_type,
0,
(wchar_t *)al_get(gnu_opt, i ),
gnu_opt.at(i).c_str(),
0,
result_mode,
condition,
@@ -84,12 +84,12 @@ static void builtin_complete_add2( const wchar_t *cmd,
flags );
}
for( i=0; i<al_get_count( old_opt ); i++ )
for( i=0; i<old_opt.size(); i++ )
{
complete_add( cmd,
cmd_type,
0,
(wchar_t *)al_get(old_opt, i ),
old_opt.at(i).c_str(),
1,
result_mode,
condition,
@@ -98,7 +98,7 @@ static void builtin_complete_add2( const wchar_t *cmd,
flags );
}
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
if( old_opt.size() == 0 && gnu_opt.size() == 0 && wcslen(short_opt) == 0 )
{
complete_add( cmd,
cmd_type,
@@ -116,11 +116,11 @@ static void builtin_complete_add2( const wchar_t *cmd,
/**
Silly function
*/
static void builtin_complete_add( array_list_t *cmd,
array_list_t *path,
static void builtin_complete_add( const wcstring_list_t &cmd,
const wcstring_list_t &path,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt,
wcstring_list_t &gnu_opt,
wcstring_list_t &old_opt,
int result_mode,
int authoritative,
const wchar_t *condition,
@@ -128,11 +128,9 @@ static void builtin_complete_add( array_list_t *cmd,
const wchar_t *desc,
int flags )
{
int i;
for( i=0; i<al_get_count( cmd ); i++ )
for( size_t i=0; i<cmd.size(); i++ )
{
builtin_complete_add2( al_get( cmd, i ),
builtin_complete_add2( cmd.at(i).c_str(),
COMMAND,
short_opt,
gnu_opt,
@@ -145,16 +143,16 @@ static void builtin_complete_add( array_list_t *cmd,
if( authoritative != -1 )
{
complete_set_authoritative( al_get( cmd, i ),
complete_set_authoritative( cmd.at(i).c_str(),
COMMAND,
authoritative );
}
}
for( i=0; i<al_get_count( path ); i++ )
for( size_t i=0; i<path.size(); i++ )
{
builtin_complete_add2( al_get( path, i ),
builtin_complete_add2( path.at(i).c_str(),
PATH,
short_opt,
gnu_opt,
@@ -167,7 +165,7 @@ static void builtin_complete_add( array_list_t *cmd,
if( authoritative != -1 )
{
complete_set_authoritative( al_get( path, i ),
complete_set_authoritative( path.at(i).c_str(),
PATH,
authoritative );
}
@@ -178,37 +176,35 @@ static void builtin_complete_add( array_list_t *cmd,
/**
Silly function
*/
static void builtin_complete_remove3( wchar_t *cmd,
static void builtin_complete_remove3( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
array_list_t *long_opt )
const wcstring_list_t &long_opt )
{
int i;
for( i=0; i<al_get_count( long_opt ); i++ )
for( size_t i=0; i<long_opt.size(); i++ )
{
complete_remove( cmd,
cmd_type,
short_opt,
(wchar_t *)al_get( long_opt, i ) );
long_opt.at(i).c_str());
}
}
/**
Silly function
*/
static void builtin_complete_remove2( wchar_t *cmd,
static void builtin_complete_remove2( const wchar_t *cmd,
int cmd_type,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt )
const wcstring_list_t &gnu_opt,
const wcstring_list_t &old_opt )
{
const wchar_t *s = (wchar_t *)short_opt;
if( *s )
{
for( ; *s; s++ )
{
if( al_get_count( old_opt) + al_get_count( gnu_opt ) == 0 )
if( old_opt.size() == 0 && gnu_opt.size() == 0 )
{
complete_remove(cmd,
cmd_type,
@@ -248,27 +244,24 @@ static void builtin_complete_remove2( wchar_t *cmd,
/**
Silly function
*/
static void builtin_complete_remove( array_list_t *cmd,
array_list_t *path,
static void builtin_complete_remove( const wcstring_list_t &cmd,
const wcstring_list_t &path,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt )
{
int i;
for( i=0; i<al_get_count( cmd ); i++ )
const wcstring_list_t &gnu_opt,
const wcstring_list_t &old_opt )
{
for( size_t i=0; i<cmd.size(); i++ )
{
builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
builtin_complete_remove2( cmd.at(i).c_str(),
COMMAND,
short_opt,
gnu_opt,
old_opt );
}
for( i=0; i<al_get_count( path ); i++ )
for( size_t i=0; i<path.size(); i++ )
{
builtin_complete_remove2( (wchar_t *)al_get( path, i ),
builtin_complete_remove2( path.at(i).c_str(),
PATH,
short_opt,
gnu_opt,
@@ -280,6 +273,7 @@ static void builtin_complete_remove( array_list_t *cmd,
const wchar_t *builtin_complete_get_temporary_buffer()
{
ASSERT_IS_MAIN_THREAD();
return temporary_buffer;
}
@@ -288,44 +282,35 @@ const wchar_t *builtin_complete_get_temporary_buffer()
tab-completions. Calls the functions in complete.c for any heavy
lifting. Defined in builtin_complete.c
*/
static int builtin_complete( wchar_t **argv )
static int builtin_complete( parser_t &parser, wchar_t **argv )
{
int res=0;
ASSERT_IS_MAIN_THREAD();
bool res=false;
int argc=0;
int result_mode=SHARED;
int remove = 0;
int authoritative = -1;
int flags = COMPLETE_AUTO_SPACE;
string_buffer_t short_opt;
array_list_t gnu_opt, old_opt;
wchar_t *comp=L"", *desc=L"", *condition=L"";
wcstring short_opt;
wcstring_list_t gnu_opt, old_opt;
const wchar_t *comp=L"", *desc=L"", *condition=L"";
wchar_t *do_complete = 0;
bool do_complete = false;
wcstring do_complete_param;
array_list_t cmd;
array_list_t path;
wcstring_list_t cmd;
wcstring_list_t path;
static int recursion_level=0;
if( !is_interactive_session )
{
debug( 1, _(L"%ls: Command only available in interactive sessions"), argv[0] );
}
al_init( &cmd );
al_init( &path );
sb_init( &short_opt );
al_init( &gnu_opt );
al_init( &old_opt );
argc = builtin_count_args( argv );
woptind=0;
while( res == 0 )
while( ! res )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -413,14 +398,14 @@ static int builtin_complete( wchar_t **argv )
case 0:
if(long_options[opt_index].flag != 0)
break;
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
res = 1;
res = true;
break;
case 'x':
@@ -438,15 +423,18 @@ static int builtin_complete( wchar_t **argv )
case 'p':
case 'c':
{
wchar_t *a = unescape( woptarg, 1);
if( a )
wcstring tmp = woptarg;
if (unescape_string(tmp, 1))
{
al_push( (opt=='p'?&path:&cmd), a );
if (opt=='p')
path.push_back(tmp);
else
cmd.push_back(tmp);
}
else
{
sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
res = 1;
append_format(stderr_buffer, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
res = true;
}
break;
}
@@ -464,15 +452,15 @@ static int builtin_complete( wchar_t **argv )
break;
case 's':
sb_append( &short_opt, woptarg );
short_opt.append(woptarg);
break;
case 'l':
al_push( &gnu_opt, woptarg );
gnu_opt.push_back(woptarg);
break;
case 'o':
al_push( &old_opt, woptarg );
old_opt.push_back(woptarg);
break;
case 'a':
@@ -488,16 +476,17 @@ static int builtin_complete( wchar_t **argv )
break;
case 'C':
do_complete = woptarg?woptarg:reader_get_buffer();
do_complete = true;
do_complete_param = woptarg ? woptarg : reader_get_buffer();
break;
case 'h':
builtin_print_help( argv[0], sb_out );
builtin_print_help( parser, argv[0], stdout_buffer );
return 0;
case '?':
builtin_unknown_option( argv[0], argv[woptind-1] );
res = 1;
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
res = true;
break;
}
@@ -508,16 +497,16 @@ static int builtin_complete( wchar_t **argv )
{
if( condition && wcslen( condition ) )
{
if( parser_test( condition, 0, 0, 0 ) )
if( parser.test( condition, 0, 0, 0 ) )
{
sb_printf( sb_err,
append_format(stderr_buffer,
L"%ls: Condition '%ls' contained a syntax error\n",
argv[0],
condition );
parser_test( condition, 0, sb_err, argv[0] );
parser.test( condition, 0, &stderr_buffer, argv[0] );
res = 1;
res = true;
}
}
}
@@ -526,16 +515,16 @@ static int builtin_complete( wchar_t **argv )
{
if( comp && wcslen( comp ) )
{
if( parser_test_args( comp, 0, 0 ) )
if( parser.test_args( comp, 0, 0 ) )
{
sb_printf( sb_err,
append_format(stderr_buffer,
L"%ls: Completion '%ls' contained a syntax error\n",
argv[0],
comp );
parser_test_args( comp, sb_err, argv[0] );
parser.test_args( comp, &stderr_buffer, argv[0] );
res = 1;
res = true;
}
}
}
@@ -544,31 +533,27 @@ static int builtin_complete( wchar_t **argv )
{
if( do_complete )
{
array_list_t *comp;
int i;
const wchar_t *token;
const wchar_t *prev_temporary_buffer = temporary_buffer;
wchar_t *token;
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
parse_util_token_extent( do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, 0 );
temporary_buffer = do_complete;
const wchar_t *prev_temporary_buffer = temporary_buffer;
temporary_buffer = do_complete_param.c_str();
if( recursion_level < 1 )
{
recursion_level++;
std::vector<completion_t> comp;
complete( do_complete_param, comp, COMPLETE_DEFAULT );
comp = al_halloc( 0 );
complete( do_complete, comp );
for( i=0; i<al_get_count( comp ); i++ )
for( size_t i=0; i< comp.size() ; i++ )
{
completion_t *next = (completion_t *)al_get( comp, i );
wchar_t *prepend;
const completion_t &next = comp.at( i );
const wchar_t *prepend;
if( next->flags & COMPLETE_NO_CASE )
if( next.flags & COMPLETE_NO_CASE )
{
prepend = L"";
}
@@ -578,17 +563,16 @@ static int builtin_complete( wchar_t **argv )
}
if( next->description )
if( !(next.description).empty() )
{
sb_printf( sb_out, L"%ls%ls\t%ls\n", prepend, next->completion, next->description );
append_format(stdout_buffer, L"%ls%ls\t%ls\n", prepend, next.completion.c_str(), next.description.c_str() );
}
else
{
sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion );
append_format(stdout_buffer, L"%ls%ls\n", prepend, next.completion.c_str() );
}
}
halloc_free( comp );
recursion_level--;
}
@@ -597,36 +581,36 @@ static int builtin_complete( wchar_t **argv )
}
else if( woptind != argc )
{
sb_printf( sb_err,
append_format(stderr_buffer,
_( L"%ls: Too many arguments\n" ),
argv[0] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
res = 1;
res = true;
}
else if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) )
else if( cmd.empty() && path.empty() )
{
/* No arguments specified, meaning we print the definitions of
* all specified completions to stdout.*/
complete_print( sb_out );
complete_print( stdout_buffer );
}
else
{
if( remove )
{
builtin_complete_remove( &cmd,
&path,
(wchar_t *)short_opt.buff,
&gnu_opt,
&old_opt );
builtin_complete_remove( cmd,
path,
short_opt.c_str(),
gnu_opt,
old_opt );
}
else
{
builtin_complete_add( &cmd,
&path,
(wchar_t *)short_opt.buff,
&gnu_opt,
&old_opt,
builtin_complete_add( cmd,
path,
short_opt.c_str(),
gnu_opt,
old_opt,
result_mode,
authoritative,
condition,
@@ -638,14 +622,5 @@ static int builtin_complete( wchar_t **argv )
}
}
al_foreach( &cmd, &free );
al_foreach( &path, &free );
al_destroy( &cmd );
al_destroy( &path );
sb_destroy( &short_opt );
al_destroy( &gnu_opt );
al_destroy( &old_opt );
return res;
return res ? 1 : 0;
}

View File

@@ -43,7 +43,7 @@ enum
/**
Calculates the cpu usage (in percent) of the specified job.
*/
static int cpu_use( job_t *j )
static int cpu_use( const job_t *j )
{
double u=0;
process_t *p;
@@ -71,7 +71,7 @@ static int cpu_use( job_t *j )
/**
Print information about the specified job
*/
static void builtin_jobs_print( job_t *j, int mode, int header )
static void builtin_jobs_print( const job_t *j, int mode, int header )
{
process_t *p;
switch( mode )
@@ -84,24 +84,22 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
/*
Print table header before first job
*/
sb_append( sb_out, _( L"Job\tGroup\t" ));
stdout_buffer.append( _( L"Job\tGroup\t" ));
#ifdef HAVE__PROC_SELF_STAT
sb_append( sb_out, _( L"CPU\t" ) );
stdout_buffer.append( _( L"CPU\t" ) );
#endif
sb_append( sb_out, _( L"State\tCommand\n" ) );
stdout_buffer.append( _( L"State\tCommand\n" ) );
}
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
append_format(stdout_buffer, L"%d\t%d\t", j->job_id, j->pgid );
#ifdef HAVE__PROC_SELF_STAT
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
append_format(stdout_buffer, L"%d%%\t", cpu_use(j) );
#endif
sb_append( sb_out,
job_is_stopped(j)?_(L"stopped"):_(L"running"),
L"\t",
j->command,
L"\n",
(void *)0 );
stdout_buffer.append(job_is_stopped(j)?_(L"stopped"):_(L"running"));
stdout_buffer.append(L"\t");
stdout_buffer.append(j->command_wcstr());
stdout_buffer.append(L"\n");
break;
}
@@ -112,9 +110,9 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
/*
Print table header before first job
*/
sb_append( sb_out, _( L"Group\n" ));
stdout_buffer.append( _( L"Group\n" ));
}
sb_printf( sb_out, L"%d\n", j->pgid );
append_format(stdout_buffer, L"%d\n", j->pgid );
break;
}
@@ -125,12 +123,12 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
/*
Print table header before first job
*/
sb_append( sb_out, _( L"Procces\n" ));
stdout_buffer.append( _( L"Procces\n" ));
}
for( p=j->first_process; p; p=p->next )
{
sb_printf( sb_out, L"%d\n", p->pid );
append_format(stdout_buffer, L"%d\n", p->pid );
}
break;
}
@@ -142,12 +140,12 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
/*
Print table header before first job
*/
sb_append( sb_out, _( L"Command\n" ));
stdout_buffer.append( _( L"Command\n" ));
}
for( p=j->first_process; p; p=p->next )
{
sb_printf( sb_out, L"%ls\n", p->argv[0] );
append_format(stdout_buffer, L"%ls\n", p->argv0() );
}
break;
}
@@ -160,20 +158,20 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
/**
The jobs builtin. Used fopr printing running jobs. Defined in builtin_jobs.c.
*/
static int builtin_jobs( wchar_t **argv )
static int builtin_jobs( parser_t &parser, wchar_t **argv )
{
int argc=0;
int found=0;
int mode=JOBS_DEFAULT;
int print_last = 0;
job_t *j;
const job_t *j;
argc = builtin_count_args( argv );
woptind=0;
while( 1 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -217,12 +215,12 @@ static int builtin_jobs( wchar_t **argv )
case 0:
if(long_options[opt_index].flag != 0)
break;
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
@@ -247,11 +245,11 @@ static int builtin_jobs( wchar_t **argv )
}
case 'h':
builtin_print_help( argv[0], sb_out );
builtin_print_help( parser, argv[0], stdout_buffer );
return 0;
case '?':
builtin_unknown_option( argv[0], argv[woptind-1] );
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
return 1;
}
@@ -271,8 +269,11 @@ static int builtin_jobs( wchar_t **argv )
/*
Ignore unconstructed jobs, i.e. ourself.
*/
for( j=first_job; j; j=j->next )
job_iterator_t jobs;
const job_t *j;
while ((j = jobs.next()))
{
if( (j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) )
{
builtin_jobs_print( j, mode, !found );
@@ -291,13 +292,13 @@ static int builtin_jobs( wchar_t **argv )
for( i=woptind; i<argc; i++ )
{
long pid;
int pid;
wchar_t *end;
errno=0;
pid=wcstol( argv[i], &end, 10 );
pid=fish_wcstoi( argv[i], &end, 10 );
if( errno || *end )
{
sb_printf( sb_err,
append_format(stderr_buffer,
_( L"%ls: '%ls' is not a job\n" ),
argv[0],
argv[i] );
@@ -312,7 +313,7 @@ static int builtin_jobs( wchar_t **argv )
}
else
{
sb_printf( sb_err,
append_format(stderr_buffer,
_( L"%ls: No suitable job: %d\n" ),
argv[0],
pid );
@@ -322,8 +323,10 @@ static int builtin_jobs( wchar_t **argv )
}
else
{
for( j= first_job; j; j=j->next )
{
job_iterator_t jobs;
const job_t *j;
while ((j = jobs.next()))
{
/*
Ignore unconstructed jobs, i.e. ourself.
*/
@@ -338,7 +341,7 @@ static int builtin_jobs( wchar_t **argv )
if( !found )
{
sb_printf( sb_out,
append_format(stdout_buffer,
_( L"%ls: There are no jobs\n" ),
argv[0] );
}

View File

@@ -1,879 +0,0 @@
/** \file builtin_set.c Functions defining the set builtin
Functions used for implementing the set builtin.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
#include <sys/types.h>
#include <termios.h>
#include <signal.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "builtin.h"
#include "env.h"
#include "expand.h"
#include "common.h"
#include "wgetopt.h"
#include "proc.h"
#include "parser.h"
/**
Error message for invalid path operations
*/
#define BUILTIN_SET_PATH_ERROR L"%ls: Could not add component %ls to %ls.\n"
/**
Hint for invalid path operation with a colon
*/
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
/**
Error for mismatch between index count and elements
*/
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
/**
Test if the specified variable should be subject to path validation
*/
static int is_path_variable( const wchar_t *env )
{
return contains( env,
L"PATH",
L"CDPATH" );
}
/**
Call env_set. If this is a path variable, e.g. PATH, validate the
elements. On error, print a description of the problem to stderr.
*/
static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
{
string_buffer_t sb;
int i;
int retcode = 0;
wchar_t *val_str=0;
if( is_path_variable( key ) )
{
int error = 0;
for( i=0; i<al_get_count( val ); i++ )
{
int show_perror = 0;
int show_hint = 0;
struct stat buff;
wchar_t *dir = (wchar_t *)al_get( val, i );
if( wstat( dir, &buff ) )
{
error = 1;
show_perror = 1;
}
if( !( S_ISDIR(buff.st_mode) ) )
{
error = 1;
}
if( error )
{
wchar_t *colon;
sb_printf( sb_err,
_(BUILTIN_SET_PATH_ERROR),
L"set",
dir,
key );
colon = wcschr( dir, L':' );
if( colon && *(colon+1) )
{
show_hint = 1;
}
}
if( show_perror )
{
builtin_wperror( L"set" );
}
if( show_hint )
{
sb_printf( sb_err,
_(BUILTIN_SET_PATH_HINT),
L"set",
key,
key,
wcschr( dir, L':' )+1);
}
if( error )
{
break;
}
}
if( error )
{
return 1;
}
}
sb_init( &sb );
if( al_get_count( val ) )
{
for( i=0; i<al_get_count( val ); i++ )
{
wchar_t *next =(wchar_t *)al_get( val, i );
sb_append( &sb, next?next:L"" );
if( i<al_get_count( val )-1 )
{
sb_append( &sb, ARRAY_SEP_STR );
}
}
val_str = (wchar_t *)sb.buff;
}
switch( env_set( key, val_str, scope | ENV_USER ) )
{
case ENV_PERM:
{
sb_printf( sb_err, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key );
retcode=1;
break;
}
case ENV_INVALID:
{
sb_printf( sb_err, _(L"%ls: Unknown error"), L"set" );
retcode=1;
break;
}
}
sb_destroy( &sb );
return retcode;
}
/**
Extract indexes from a destination argument of the form name[index1 index2...]
\param indexes the list to insert the new indexes into
\param src the source string to parse
\param name the name of the element. Return null if the name in \c src does not match this name
\param var_count the number of elements in the array to parse.
\return the total number of indexes parsed, or -1 on error
*/
static int parse_index( array_list_t *indexes,
const wchar_t *src,
const wchar_t *name,
int var_count )
{
int len;
int count = 0;
const wchar_t *src_orig = src;
if (src == 0)
{
return 0;
}
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
{
src++;
}
if (*src != L'[')
{
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
return 0;
}
len = src-src_orig;
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
{
sb_printf( sb_err,
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
L"set",
name,
len,
src_orig);
return 0;
}
src++;
while (iswspace(*src))
{
src++;
}
while (*src != L']')
{
wchar_t *end;
long l_ind;
errno = 0;
l_ind = wcstol(src, &end, 10);
if( end==src || errno )
{
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
return 0;
}
if( l_ind < 0 )
{
l_ind = var_count+l_ind+1;
}
al_push_long(indexes, l_ind);
src = end;
count++;
while (iswspace(*src)) src++;
}
return count;
}
/**
Update a list \c list by writing copies (using wcsdup) of the
values specified by \c values to the indexes specified by \c
indexes. The previous entries at the specidied position will be
free'd.
\return 0 if the operation was successfull, non-zero otherwise
*/
static int update_values( array_list_t *list,
array_list_t *indexes,
array_list_t *values )
{
int i;
/* Replace values where needed */
for( i = 0; i < al_get_count(indexes); i++ )
{
/*
The '- 1' below is because the indices in fish are
one-based, but the array_list_t uses zero-based indices
*/
long ind = al_get_long(indexes, i) - 1;
void *new = (void *) al_get(values, i);
if( ind < 0 )
{
return 1;
}
free((void *) al_get(list, ind));
al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L""));
}
return 0;
}
/**
Return 1 if an array list of longs contains the specified
value, 0 otherwise
*/
static int al_contains_long( array_list_t *list,
long val)
{
int i;
for (i = 0; i < al_get_count(list); i++)
{
long current = al_get_long(list, i);
if( current != 0 && current == val )
{
return 1;
}
}
return 0;
}
/**
Erase from a list values at specified indexes
*/
static void erase_values(array_list_t *list, array_list_t *indexes)
{
long i;
array_list_t result;
al_init(&result);
for (i = 0; i < al_get_count(list); i++)
{
if (!al_contains_long(indexes, i + 1))
{
al_push(&result, al_get(list, i));
}
else
{
free( (void *)al_get(list, i));
}
}
al_truncate(list,0);
al_push_all( list, &result );
al_destroy(&result);
}
/**
Print the names of all environment variables in the scope, with or without values,
with or without escaping
*/
static void print_variables(int include_values, int esc, int scope)
{
array_list_t names;
int i;
al_init( &names );
env_get_names( &names, scope );
sort_list( &names );
for( i = 0; i < al_get_count(&names); i++ )
{
wchar_t *key = (wchar_t *)al_get( &names, i );
wchar_t *e_key = esc ? escape(key, 0) : wcsdup(key);
sb_append(sb_out, e_key);
if( include_values )
{
wchar_t *value = env_get(key);
wchar_t *e_value;
if( value )
{
int shorten = 0;
if( wcslen( value ) > 64 )
{
shorten = 1;
value = wcsndup( value, 60 );
if( !value )
{
DIE_MEM();
}
}
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
sb_append(sb_out, L" ", e_value, (void *)0);
free(e_value);
if( shorten )
{
sb_append(sb_out, L"\u2026");
free( value );
}
}
}
sb_append(sb_out, L"\n");
free(e_key);
}
al_destroy(&names);
}
/**
The set builtin. Creates, updates and erases environment variables
and environemnt variable arrays.
*/
static int builtin_set( wchar_t **argv )
{
/**
Variables used for parsing the argument list
*/
const static struct woption
long_options[] =
{
{
L"export", no_argument, 0, 'x'
}
,
{
L"global", no_argument, 0, 'g'
}
,
{
L"local", no_argument, 0, 'l'
}
,
{
L"erase", no_argument, 0, 'e'
}
,
{
L"names", no_argument, 0, 'n'
}
,
{
L"unexport", no_argument, 0, 'u'
}
,
{
L"universal", no_argument, 0, 'U'
}
,
{
L"query", no_argument, 0, 'q'
}
,
{
L"help", no_argument, 0, 'h'
}
,
{
0, 0, 0, 0
}
}
;
const wchar_t *short_options = L"+xglenuUqh";
int argc = builtin_count_args(argv);
/*
Flags to set the work mode
*/
int local = 0, global = 0, export = 0;
int erase = 0, list = 0, unexport=0;
int universal = 0, query=0;
/*
Variables used for performing the actual work
*/
wchar_t *dest = 0;
int retcode=0;
int scope;
int slice=0;
int i;
wchar_t *bad_char;
/* Parse options to obtain the requested operation and the modifiers */
woptind = 0;
while (1)
{
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1)
{
break;
}
switch(c)
{
case 0:
break;
case 'e':
erase = 1;
break;
case 'n':
list = 1;
break;
case 'x':
export = 1;
break;
case 'l':
local = 1;
break;
case 'g':
global = 1;
break;
case 'u':
unexport = 1;
break;
case 'U':
universal = 1;
break;
case 'q':
query = 1;
break;
case 'h':
builtin_print_help( argv[0], sb_out );
return 0;
case '?':
builtin_unknown_option( argv[0], argv[woptind-1] );
return 1;
default:
break;
}
}
/*
Ok, all arguments have been parsed, let's validate them
*/
/*
If we are checking the existance of a variable (-q) we can not
also specify scope
*/
if( query && (erase || list || global || local || universal || export || unexport ) )
{
sb_printf(sb_err,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
/* We can't both list and erase varaibles */
if( erase && list )
{
sb_printf(sb_err,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
/*
Variables can only have one scope
*/
if( local + global + universal > 1 )
{
sb_printf( sb_err,
BUILTIN_ERR_GLOCAL,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
/*
Variables can only have one export status
*/
if( export && unexport )
{
sb_printf( sb_err,
BUILTIN_ERR_EXPUNEXP,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
/*
Calculate the scope value for variable assignement
*/
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
if( query )
{
/*
Query mode. Return the number of variables that do not exist
out of the specified variables.
*/
int i;
for( i=woptind; i<argc; i++ )
{
wchar_t *arg = argv[i];
int slice=0;
if( !(dest = wcsdup(arg)))
{
DIE_MEM();
}
if( wcschr( dest, L'[' ) )
{
slice = 1;
*wcschr( dest, L'[' )=0;
}
if( slice )
{
array_list_t indexes;
array_list_t result;
int j;
al_init( &result );
al_init( &indexes );
tokenize_variable_array( env_get( dest ), &result );
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
{
builtin_print_help( argv[0], sb_err );
retcode = 1;
break;
}
for( j=0; j<al_get_count( &indexes ); j++ )
{
long idx = al_get_long( &indexes, j );
if( idx < 1 || idx > al_get_count( &result ) )
{
retcode++;
}
}
}
else
{
if( !env_exist( arg, scope ) )
{
retcode++;
}
}
free( dest );
}
return retcode;
}
if( list )
{
/* Maybe we should issue an error if there are any other arguments? */
print_variables(0, 0, scope);
return 0;
}
if( woptind == argc )
{
/*
Print values of variables
*/
if( erase )
{
sb_printf( sb_err,
_(L"%ls: Erase needs a variable name\n%ls\n"),
argv[0] );
builtin_print_help( argv[0], sb_err );
retcode = 1;
}
else
{
print_variables( 1, 1, scope );
}
return retcode;
}
if( !(dest = wcsdup(argv[woptind])))
{
DIE_MEM();
}
if( wcschr( dest, L'[' ) )
{
slice = 1;
*wcschr( dest, L'[' )=0;
}
if( !wcslen( dest ) )
{
free( dest );
sb_printf( sb_err, BUILTIN_ERR_VARNAME_ZERO, argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
if( (bad_char = wcsvarname( dest ) ) )
{
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
builtin_print_help( argv[0], sb_err );
free( dest );
return 1;
}
if( slice && erase && (scope != ENV_USER) )
{
free( dest );
sb_printf( sb_err, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
/*
set assignment can work in two modes, either using slices or
using the whole array. We detect which mode is used here.
*/
if( slice )
{
/*
Slice mode
*/
int idx_count, val_count;
array_list_t values;
array_list_t indexes;
array_list_t result;
al_init(&values);
al_init(&indexes);
al_init(&result);
tokenize_variable_array( env_get(dest), &result );
for( ; woptind<argc; woptind++ )
{
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )
{
builtin_print_help( argv[0], sb_err );
retcode = 1;
break;
}
val_count = argc-woptind-1;
idx_count = al_get_count( &indexes );
if( !erase )
{
if( val_count < idx_count )
{
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), argv[0] );
builtin_print_help( argv[0], sb_err );
retcode=1;
break;
}
if( val_count == idx_count )
{
woptind++;
break;
}
}
}
if( !retcode )
{
/*
Slice indexes have been calculated, do the actual work
*/
if( erase )
{
erase_values(&result, &indexes);
my_env_set( dest, &result, scope);
}
else
{
array_list_t value;
al_init(&value);
while( woptind < argc )
{
al_push(&value, argv[woptind++]);
}
if( update_values( &result,
&indexes,
&value ) )
{
sb_printf( sb_err, L"%ls: ", argv[0] );
sb_printf( sb_err, ARRAY_BOUNDS_ERR );
sb_append( sb_err, L"\n" );
}
my_env_set(dest,
&result,
scope);
al_destroy( &value );
}
}
al_foreach( &result, &free );
al_destroy( &result );
al_destroy(&indexes);
al_destroy(&values);
}
else
{
woptind++;
/*
No slicing
*/
if( erase )
{
if( woptind != argc )
{
sb_printf( sb_err,
_(L"%ls: Values cannot be specfied with erase\n"),
argv[0] );
builtin_print_help( argv[0], sb_err );
retcode=1;
}
else
{
retcode = env_remove( dest, scope );
}
}
else
{
array_list_t val;
al_init( &val );
for( i=woptind; i<argc; i++ )
{
al_push( &val, argv[i] );
}
retcode = my_env_set( dest, &val, scope );
al_destroy( &val );
}
}
free( dest );
return retcode;
}

836
builtin_set.cpp Normal file
View File

@@ -0,0 +1,836 @@
/** \file builtin_set.c Functions defining the set builtin
Functions used for implementing the set builtin.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
#include <sys/types.h>
#include <termios.h>
#include <signal.h>
#include <vector>
#include <algorithm>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "builtin.h"
#include "env.h"
#include "expand.h"
#include "common.h"
#include "wgetopt.h"
#include "proc.h"
#include "parser.h"
/* We know about these buffers */
extern wcstring stdout_buffer, stderr_buffer;
/**
Error message for invalid path operations
*/
#define BUILTIN_SET_PATH_ERROR L"%ls: Warning: path component %ls may not be valid in %ls.\n"
/**
Hint for invalid path operation with a colon
*/
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
/**
Error for mismatch between index count and elements
*/
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
/**
Test if the specified variable should be subject to path validation
*/
static int is_path_variable( const wchar_t *env )
{
return contains(env, L"PATH", L"CDPATH" );
}
/**
Call env_set. If this is a path variable, e.g. PATH, validate the
elements. On error, print a description of the problem to stderr.
*/
static int my_env_set( const wchar_t *key, const wcstring_list_t &val, int scope )
{
size_t i;
int retcode = 0;
const wchar_t *val_str=NULL;
if( is_path_variable( key ) )
{
/* Fix for https://github.com/fish-shell/fish-shell/issues/199 . Return success if any path setting succeeds. */
bool any_success = false, any_error = false;
for( i=0; i< val.size() ; i++ )
{
bool show_perror = false;
int show_hint = 0;
bool error = false;
struct stat buff;
const wchar_t *dir = val[i].c_str();
if( wstat( dir, &buff ) )
{
error = true;
show_perror = true;
}
if( !( S_ISDIR(buff.st_mode) ) )
{
error = true;
}
if( !error )
{
any_success = true;
}
else
{
any_error = true;
const wchar_t *colon;
append_format(stderr_buffer, _(BUILTIN_SET_PATH_ERROR), L"set", dir, key);
colon = wcschr( dir, L':' );
if( colon && *(colon+1) )
{
show_hint = 1;
}
}
if( show_perror )
{
builtin_wperror( L"set" );
}
if( show_hint )
{
append_format(stderr_buffer, _(BUILTIN_SET_PATH_HINT), L"set", key, key, wcschr( dir, L':' )+1);
}
}
/* Fail at setting the path if we tried to set it to something non-empty, but it wound up empty. */
if( ! val.empty() && ! any_success )
{
return 1;
}
}
wcstring sb;
if( val.size() )
{
for( i=0; i< val.size() ; i++ )
{
sb.append(val[i]);
if( i<val.size() - 1 )
{
sb.append( ARRAY_SEP_STR );
}
}
val_str = sb.c_str();
}
switch( env_set( key, val_str, scope | ENV_USER ) )
{
case ENV_PERM:
{
append_format(stderr_buffer, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key);
retcode=1;
break;
}
case ENV_INVALID:
{
append_format(stderr_buffer, _(L"%ls: Unknown error"), L"set" );
retcode=1;
break;
}
}
return retcode;
}
/**
Extract indexes from a destination argument of the form name[index1 index2...]
\param indexes the list to insert the new indexes into
\param src the source string to parse
\param name the name of the element. Return null if the name in \c src does not match this name
\param var_count the number of elements in the array to parse.
\return the total number of indexes parsed, or -1 on error
*/
static int parse_index( std::vector<long> &indexes,
const wchar_t *src,
const wchar_t *name,
size_t var_count )
{
size_t len;
int count = 0;
const wchar_t *src_orig = src;
if (src == 0)
{
return 0;
}
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
{
src++;
}
if (*src != L'[')
{
append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), L"set" );
return 0;
}
len = src-src_orig;
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
{
append_format(stderr_buffer,
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
L"set",
name,
len,
src_orig);
return 0;
}
src++;
while (iswspace(*src))
{
src++;
}
while (*src != L']')
{
wchar_t *end;
long l_ind;
errno = 0;
l_ind = wcstol(src, &end, 10);
if( end==src || errno )
{
append_format(stderr_buffer, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
return 0;
}
if( l_ind < 0 )
{
l_ind = var_count+l_ind+1;
}
src = end;
if ( *src==L'.' && *(src+1)==L'.' ){
src+=2;
long l_ind2 = wcstol( src, &end, 10 );
if( end==src || errno )
{
return 1;
}
src = end;
if( l_ind2 < 0 )
{
l_ind2 = var_count+l_ind2+1;
}
int direction = l_ind2<l_ind ? -1 : 1 ;
for (long jjj = l_ind; jjj*direction <= l_ind2*direction; jjj+=direction) {
// debug(0, L"Expand range [set]: %i\n", jjj);
indexes.push_back( jjj );
count++;
}
}
else {
indexes.push_back( l_ind );
count++;
}
while (iswspace(*src)) src++;
}
return count;
}
static int update_values( wcstring_list_t &list,
std::vector<long> &indexes,
wcstring_list_t &values )
{
size_t i;
/* Replace values where needed */
for( i = 0; i < indexes.size(); i++ )
{
/*
The '- 1' below is because the indices in fish are
one-based, but the vector uses zero-based indices
*/
long ind = indexes[i] - 1;
const wcstring newv = values[ i ];
if( ind < 0 )
{
return 1;
}
if ( (size_t)ind >= list.size() )
{
list.resize( ind+1 );
}
// free((void *) al_get(list, ind));
list[ ind ] = newv;
}
return 0;
}
/**
Erase from a list of wcstring values at specified indexes
*/
static void erase_values(wcstring_list_t &list, const std::vector<long> &indexes)
{
// Make a set of indexes.
// This both sorts them into ascending order and removes duplicates.
const std::set<long> indexes_set(indexes.begin(), indexes.end());
// Now walk the set backwards, so we encounter larger indexes first, and remove elements at the given (1-based) indexes.
std::set<long>::const_reverse_iterator iter;
for (iter = indexes_set.rbegin(); iter != indexes_set.rend(); iter++) {
long val = *iter;
if (val > 0 && (size_t)val <= list.size()) {
// One-based indexing!
list.erase(list.begin() + val - 1);
}
}
}
/**
Print the names of all environment variables in the scope, with or without shortening,
with or without values, with or without escaping
*/
static void print_variables(int include_values, int esc, bool shorten_ok, int scope)
{
wcstring_list_t names = env_get_names(scope);
sort(names.begin(), names.end());
for( size_t i = 0; i < names.size(); i++ )
{
const wcstring key = names.at(i);
const wcstring e_key = escape_string(key, 0);
stdout_buffer.append(e_key);
if( include_values )
{
env_var_t value = env_get_string(key);
if( !value.missing() )
{
int shorten = 0;
if( shorten_ok && value.length() > 64 )
{
shorten = 1;
value.resize(60);
}
wcstring e_value = esc ? expand_escape_variable(value) : value;
stdout_buffer.append(L" ");
stdout_buffer.append(e_value);
if( shorten )
{
stdout_buffer.append(L"\u2026");
}
}
}
stdout_buffer.append(L"\n");
}
}
/**
The set builtin. Creates, updates and erases environment variables
and environemnt variable arrays.
*/
static int builtin_set( parser_t &parser, wchar_t **argv )
{
/**
Variables used for parsing the argument list
*/
static const struct woption
long_options[] =
{
{
L"export", no_argument, 0, 'x'
}
,
{
L"global", no_argument, 0, 'g'
}
,
{
L"local", no_argument, 0, 'l'
}
,
{
L"erase", no_argument, 0, 'e'
}
,
{
L"names", no_argument, 0, 'n'
}
,
{
L"unexport", no_argument, 0, 'u'
}
,
{
L"universal", no_argument, 0, 'U'
}
,
{
L"long", no_argument, 0, 'L'
}
,
{
L"query", no_argument, 0, 'q'
}
,
{
L"help", no_argument, 0, 'h'
}
,
{
0, 0, 0, 0
}
}
;
const wchar_t *short_options = L"+xglenuULqh";
int argc = builtin_count_args(argv);
/*
Flags to set the work mode
*/
int local = 0, global = 0, exportv = 0;
int erase = 0, list = 0, unexport=0;
int universal = 0, query=0;
bool shorten_ok = true;
/*
Variables used for performing the actual work
*/
wchar_t *dest = 0;
int retcode=0;
int scope;
int slice=0;
int i;
wchar_t *bad_char;
/* Parse options to obtain the requested operation and the modifiers */
woptind = 0;
while (1)
{
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1)
{
break;
}
switch(c)
{
case 0:
break;
case 'e':
erase = 1;
break;
case 'n':
list = 1;
break;
case 'x':
exportv = 1;
break;
case 'l':
local = 1;
break;
case 'g':
global = 1;
break;
case 'u':
unexport = 1;
break;
case 'U':
universal = 1;
break;
case 'L':
shorten_ok = false;
break;
case 'q':
query = 1;
break;
case 'h':
builtin_print_help( parser, argv[0], stdout_buffer );
return 0;
case '?':
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
return 1;
default:
break;
}
}
/*
Ok, all arguments have been parsed, let's validate them
*/
/*
If we are checking the existance of a variable (-q) we can not
also specify scope
*/
if( query && (erase || list) )
{
append_format(stderr_buffer,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
/* We can't both list and erase varaibles */
if( erase && list )
{
append_format(stderr_buffer,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
/*
Variables can only have one scope
*/
if( local + global + universal > 1 )
{
append_format(stderr_buffer,
BUILTIN_ERR_GLOCAL,
argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
/*
Variables can only have one export status
*/
if( exportv && unexport )
{
append_format(stderr_buffer,
BUILTIN_ERR_EXPUNEXP,
argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
/*
Calculate the scope value for variable assignement
*/
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (exportv ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
if( query )
{
/*
Query mode. Return the number of variables that do not exist
out of the specified variables.
*/
int i;
for( i=woptind; i<argc; i++ )
{
wchar_t *arg = argv[i];
int slice=0;
if( !(dest = wcsdup(arg)))
{
DIE_MEM();
}
if( wcschr( dest, L'[' ) )
{
slice = 1;
*wcschr( dest, L'[' )=0;
}
if( slice )
{
std::vector<long> indexes;
wcstring_list_t result;
size_t j;
env_var_t dest_str = env_get_string(dest);
if (! dest_str.missing())
tokenize_variable_array( dest_str, result );
if( !parse_index( indexes, arg, dest, result.size() ) )
{
builtin_print_help( parser, argv[0], stderr_buffer );
retcode = 1;
break;
}
for( j=0; j < indexes.size() ; j++ )
{
long idx = indexes[j];
if( idx < 1 || (size_t)idx > result.size() )
{
retcode++;
}
}
}
else
{
if( !env_exist( arg, scope ) )
{
retcode++;
}
}
free( dest );
}
return retcode;
}
if( list )
{
/* Maybe we should issue an error if there are any other arguments? */
print_variables(0, 0, shorten_ok, scope);
return 0;
}
if( woptind == argc )
{
/*
Print values of variables
*/
if( erase )
{
append_format(stderr_buffer,
_(L"%ls: Erase needs a variable name\n"),
argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
retcode = 1;
}
else
{
print_variables( 1, 1, shorten_ok, scope );
}
return retcode;
}
if( !(dest = wcsdup(argv[woptind])))
{
DIE_MEM();
}
if( wcschr( dest, L'[' ) )
{
slice = 1;
*wcschr( dest, L'[' )=0;
}
if( !wcslen( dest ) )
{
free( dest );
append_format(stderr_buffer, BUILTIN_ERR_VARNAME_ZERO, argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
if( (bad_char = wcsvarname( dest ) ) )
{
append_format(stderr_buffer, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
builtin_print_help( parser, argv[0], stderr_buffer );
free( dest );
return 1;
}
if( slice && erase && (scope != ENV_USER) )
{
free( dest );
append_format(stderr_buffer, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
/*
set assignment can work in two modes, either using slices or
using the whole array. We detect which mode is used here.
*/
if( slice )
{
/*
Slice mode
*/
size_t idx_count, val_count;
wcstring_list_t values;
std::vector<long> indexes;
wcstring_list_t result;
const env_var_t dest_str = env_get_string(dest);
if (! dest_str.missing())
tokenize_variable_array( dest_str, result );
for( ; woptind<argc; woptind++ )
{
if( !parse_index( indexes, argv[woptind], dest, result.size() ) )
{
builtin_print_help( parser, argv[0], stderr_buffer );
retcode = 1;
break;
}
val_count = argc-woptind-1;
idx_count = indexes.size();
if( !erase )
{
if( val_count < idx_count )
{
append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
retcode=1;
break;
}
if( val_count == idx_count )
{
woptind++;
break;
}
}
}
if( !retcode )
{
/*
Slice indexes have been calculated, do the actual work
*/
if( erase )
{
erase_values(result, indexes);
my_env_set( dest, result, scope);
}
else
{
wcstring_list_t value;
// al_init(&value);
while( woptind < argc )
{
value.push_back( argv[woptind++] );
}
if( update_values( result,
indexes,
value ) )
{
append_format(stderr_buffer, L"%ls: ", argv[0] );
append_format(stderr_buffer, ARRAY_BOUNDS_ERR );
stderr_buffer.push_back(L'\n');
}
my_env_set(dest, result, scope);
// al_destroy( &value );
}
}
// al_foreach( &result, &free );
// al_destroy( &result );
// al_destroy(&indexes);
// al_destroy(&values);
}
else
{
woptind++;
/*
No slicing
*/
if( erase )
{
if( woptind != argc )
{
append_format(stderr_buffer,
_(L"%ls: Values cannot be specfied with erase\n"),
argv[0] );
builtin_print_help( parser, argv[0], stderr_buffer );
retcode=1;
}
else
{
retcode = env_remove( dest, scope );
}
}
else
{
wcstring_list_t val;
for( i=woptind; i<argc; i++ )
val.push_back(argv[i]);
retcode = my_env_set( dest, val, scope );
}
}
free( dest );
return retcode;
}

745
builtin_test.cpp Normal file
View File

@@ -0,0 +1,745 @@
/** \file builtin_test.cpp Functions defining the test builtin
Functions used for implementing the test builtin.
Implemented from scratch (yes, really) by way of IEEE 1003.1 as reference.
*/
#include "config.h"
#include "common.h"
#include "builtin.h"
#include "wutil.h"
#include "proc.h"
#include <sys/stat.h>
#include <memory>
enum {
BUILTIN_TEST_SUCCESS = STATUS_BUILTIN_OK,
BUILTIN_TEST_FAIL = STATUS_BUILTIN_ERROR
};
int builtin_test( parser_t &parser, wchar_t **argv );
static const wchar_t * const condstr[] = {
L"!", L"&&", L"||", L"==", L"!=", L"<", L">", L"-nt", L"-ot", L"-ef", L"-eq",
L"-ne", L"-lt", L"-gt", L"-le", L"-ge", L"=~"
};
namespace test_expressions {
enum token_t {
test_unknown, // arbitrary string
test_bang, // "!", inverts sense
test_filetype_b, // "-b", for block special files
test_filetype_c, // "-c" for character special files
test_filetype_d, // "-d" for directories
test_filetype_e, // "-e" for files that exist
test_filetype_f, // "-f" for for regular files
test_filetype_g, // "-g" for set-group-id
test_filetype_h, // "-h" for symbolic links
test_filetype_L, // "-L", same as -h
test_filetype_p, // "-p", for FIFO
test_filetype_S, // "-S", socket
test_filesize_s, // "-s", size greater than zero
test_filedesc_t, // "-t", whether the fd is associated with a terminal
test_fileperm_r, // "-r", read permission
test_fileperm_u, // "-u", whether file is setuid
test_fileperm_w, // "-w", whether file write permission is allowed
test_fileperm_x, // "-x", whether file execute/search is allowed
test_string_n, // "-n", non-empty string
test_string_z, // "-z", true if length of string is 0
test_string_equal, // "=", true if strings are identical
test_string_not_equal, // "!=", true if strings are not identical
test_number_equal, // "-eq", true if numbers are equal
test_number_not_equal, // "-ne", true if numbers are not equal
test_number_greater, // "-gt", true if first number is larger than second
test_number_greater_equal, // "-ge", true if first number is at least second
test_number_lesser, // "-lt", true if first number is smaller than second
test_number_lesser_equal, // "-le", true if first number is at most second
test_combine_and, // "-a", true if left and right are both true
test_combine_or, // "-o", true if either left or right is true
test_paren_open, // "(", open paren
test_paren_close, // ")", close paren
};
static bool binary_primary_evaluate(test_expressions::token_t token, const wcstring &left, const wcstring &right, wcstring_list_t &errors);
static bool unary_primary_evaluate(test_expressions::token_t token, const wcstring &arg, wcstring_list_t &errors);
enum {
UNARY_PRIMARY = 1 << 0,
BINARY_PRIMARY = 1 << 1
};
static const struct token_info_t { token_t tok; const wchar_t *string; unsigned int flags; } token_infos[] =
{
{test_unknown, L"", 0},
{test_bang, L"!", 0},
{test_filetype_b, L"-b", UNARY_PRIMARY},
{test_filetype_c, L"-c", UNARY_PRIMARY},
{test_filetype_d, L"-d", UNARY_PRIMARY},
{test_filetype_e, L"-e", UNARY_PRIMARY},
{test_filetype_f, L"-f", UNARY_PRIMARY},
{test_filetype_g, L"-g", UNARY_PRIMARY},
{test_filetype_h, L"-h", UNARY_PRIMARY},
{test_filetype_L, L"-L", UNARY_PRIMARY},
{test_filetype_p, L"-p", UNARY_PRIMARY},
{test_filetype_S, L"-S", UNARY_PRIMARY},
{test_filesize_s, L"-s", UNARY_PRIMARY},
{test_filedesc_t, L"-t", UNARY_PRIMARY},
{test_fileperm_r, L"-r", UNARY_PRIMARY},
{test_fileperm_u, L"-u", UNARY_PRIMARY},
{test_fileperm_w, L"-w", UNARY_PRIMARY},
{test_fileperm_x, L"-x", UNARY_PRIMARY},
{test_string_n, L"-n", UNARY_PRIMARY},
{test_string_z, L"-z", UNARY_PRIMARY},
{test_string_equal, L"=", BINARY_PRIMARY},
{test_string_not_equal, L"!=", BINARY_PRIMARY},
{test_number_equal, L"-eq", BINARY_PRIMARY},
{test_number_not_equal, L"-ne", BINARY_PRIMARY},
{test_number_greater, L"-gt", BINARY_PRIMARY},
{test_number_greater_equal, L"-ge", BINARY_PRIMARY},
{test_number_lesser, L"-lt", BINARY_PRIMARY},
{test_number_lesser_equal, L"-le", BINARY_PRIMARY},
{test_combine_and, L"-a", 0},
{test_combine_or, L"-o", 0},
{test_paren_open, L"(", 0},
{test_paren_close, L")", 0}
};
const token_info_t *token_for_string(const wcstring &str) {
for (size_t i=0; i < sizeof token_infos / sizeof *token_infos; i++) {
if (str == token_infos[i].string) {
return &token_infos[i];
}
}
return &token_infos[0]; //unknown
}
/* Grammar.
<expr> = <combining_expr>
<combining_expr> = <unary_expr> and/or <combining_expr> |
<unary_expr>
<unary_expr> = bang <unary_expr> |
<primary>
<primary> = <unary_primary> arg |
arg <binary_primary> arg |
'(' <expr> ')'
*/
class expression;
class test_parser {
private:
wcstring_list_t strings;
wcstring_list_t errors;
expression *error(const wchar_t *fmt, ...);
void add_error(const wchar_t *fmt, ...);
const wcstring &arg(unsigned int idx) { return strings.at(idx); }
public:
test_parser(const wcstring_list_t &val) : strings(val)
{ }
expression *parse_expression(unsigned int start, unsigned int end);
expression *parse_combining_expression(unsigned int start, unsigned int end);
expression *parse_unary_expression(unsigned int start, unsigned int end);
expression *parse_primary(unsigned int start, unsigned int end);
expression *parse_parenthentical(unsigned int start, unsigned int end);
expression *parse_unary_primary(unsigned int start, unsigned int end);
expression *parse_binary_primary(unsigned int start, unsigned int end);
expression *parse_just_a_string(unsigned int start, unsigned int end);
static expression *parse_args(const wcstring_list_t &args, wcstring &err);
};
struct range_t {
unsigned int start;
unsigned int end;
range_t(unsigned s, unsigned e) : start(s), end(e) { }
};
/* Base class for expressions */
class expression {
protected:
expression(token_t what, range_t where) : token(what), range(where) { }
public:
const token_t token;
range_t range;
virtual ~expression() { }
// evaluate returns true if the expression is true (i.e. BUILTIN_TEST_SUCCESS)
virtual bool evaluate(wcstring_list_t &errors) = 0;
};
typedef std::auto_ptr<expression> expr_ref_t;
/* Single argument like -n foo or "just a string" */
class unary_primary : public expression {
public:
wcstring arg;
unary_primary(token_t tok, range_t where, const wcstring &what) : expression(tok, where), arg(what) { }
bool evaluate(wcstring_list_t &errors);
};
/* Two argument primary like foo != bar */
class binary_primary : public expression {
public:
wcstring arg_left;
wcstring arg_right;
binary_primary(token_t tok, range_t where, const wcstring &left, const wcstring &right) : expression(tok, where), arg_left(left), arg_right(right)
{ }
bool evaluate(wcstring_list_t &errors);
};
/* Unary operator like bang */
class unary_operator : public expression {
public:
expr_ref_t subject;
unary_operator(token_t tok, range_t where, expr_ref_t &exp) : expression(tok, where), subject(exp) { }
bool evaluate(wcstring_list_t &errors);
};
/* Combining expression. Contains a list of AND or OR expressions. It takes more than two so that we don't have to worry about precedence in the parser. */
class combining_expression : public expression {
public:
const std::vector<expression *> subjects;
const std::vector<token_t> combiners;
combining_expression(token_t tok, range_t where, const std::vector<expression *> &exprs, const std::vector<token_t> &combs) : expression(tok, where), subjects(exprs), combiners(combs)
{
/* We should have one more subject than combiner */
assert(subjects.size() == combiners.size() + 1);
}
/* We are responsible for destroying our expressions */
virtual ~combining_expression() {
for (size_t i=0; i < subjects.size(); i++) {
delete subjects[i];
}
}
bool evaluate(wcstring_list_t &errors);
};
/* Parenthetical expression */
class parenthetical_expression : public expression {
public:
expr_ref_t contents;
parenthetical_expression(token_t tok, range_t where, expr_ref_t &expr) : expression(tok, where), contents(expr) { }
virtual bool evaluate(wcstring_list_t &errors);
};
void test_parser::add_error(const wchar_t *fmt, ...) {
assert(fmt != NULL);
va_list va;
va_start(va, fmt);
this->errors.push_back(vformat_string(fmt, va));
va_end(va);
}
expression *test_parser::error(const wchar_t *fmt, ...) {
assert(fmt != NULL);
va_list va;
va_start(va, fmt);
this->errors.push_back(vformat_string(fmt, va));
va_end(va);
return NULL;
}
expression *test_parser::parse_unary_expression(unsigned int start, unsigned int end) {
if (start >= end) {
return error(L"Missing argument at index %u", start);
}
token_t tok = token_for_string(arg(start))->tok;
if (tok == test_bang) {
expr_ref_t subject(parse_unary_expression(start + 1, end));
if (subject.get()) {
return new unary_operator(tok, range_t(start, subject->range.end), subject);
} else {
return NULL;
}
} else {
return parse_primary(start, end);
}
}
/* Parse a combining expression (AND, OR) */
expression *test_parser::parse_combining_expression(unsigned int start, unsigned int end) {
if (start >= end)
return NULL;
std::vector<expression *> subjects;
std::vector<token_t> combiners;
unsigned int idx = start;
while (idx < end) {
if (! subjects.empty()) {
/* This is not the first expression, so we expect a combiner. */
token_t combiner = token_for_string(arg(idx))->tok;
if (combiner != test_combine_and && combiner != test_combine_or) {
/* Not a combiner, we're done */
break;
}
combiners.push_back(combiner);
idx++;
}
/* Parse another expression */
expression *expr = parse_unary_expression(idx, end);
if (! expr) {
add_error(L"Missing argument at index %u", idx);
break;
}
/* Go to the end of this expression */
idx = expr->range.end;
subjects.push_back(expr);
}
if (! subjects.empty()) {
/* Our new expression takes ownership of all expressions we created. The token we pass is irrelevant. */
return new combining_expression(test_combine_and, range_t(start, idx), subjects, combiners);
} else {
/* No subjects */
return NULL;
}
}
expression *test_parser::parse_unary_primary(unsigned int start, unsigned int end) {
/* We need two arguments */
if (start >= end) {
return error(L"Missing argument at index %u", start);
}
if (start + 1 >= end) {
return error(L"Missing argument at index %u", start + 1);
}
/* All our unary primaries are prefix, so the operator is at start. */
const token_info_t *info = token_for_string(arg(start));
if (! (info->flags & UNARY_PRIMARY))
return NULL;
return new unary_primary(info->tok, range_t(start, start + 2), arg(start + 1));
}
expression *test_parser::parse_just_a_string(unsigned int start, unsigned int end) {
/* Handle a string as a unary primary that is not a token of any other type.
e.g. 'test foo -a bar' should evaluate to true
We handle this with a unary primary of test_string_n
*/
/* We need one arguments */
if (start >= end) {
return error(L"Missing argument at index %u", start);
}
const token_info_t *info = token_for_string(arg(start));
if (info->tok != test_unknown) {
return error(L"Unexpected argument type at index %u", start);
}
/* This is hackish; a nicer way to implement this would be with a "just a string" expression type */
return new unary_primary(test_string_n, range_t(start, start + 1), arg(start));
}
#if 0
expression *test_parser::parse_unary_primary(unsigned int start, unsigned int end) {
/* We need either one or two arguments */
if (start >= end) {
return error(L"Missing argument at index %u", start);
}
/* The index of the argument to the unary primary */
unsigned int arg_idx;
/* All our unary primaries are prefix, so any operator is at start. But it also may just be a string, with no operator. */
const token_info_t *info = token_for_string(arg(start));
if (info->flags & UNARY_PRIMARY) {
/* We have an operator. Skip the operator argument */
arg_idx = start + 1;
/* We have some freedom here...do we allow other tokens for the argument to operate on?
For example, should 'test -n =' work? I say yes. So no typechecking on the next token. */
} else if (info->tok == test_unknown) {
/* "Just a string. */
arg_idx = start;
} else {
/* Here we don't allow arbitrary tokens as "just a string." I.e. 'test = -a =' should have a parse error. We could relax this at some point. */
return error(L"Parse error at argument index %u", start);
}
/* Verify we have the argument we want, i.e. test -n should fail to parse */
if (arg_idx >= end) {
return error(L"Missing argument at index %u", arg_idx);
}
return new unary_primary(info->tok, range_t(start, arg_idx + 1), arg(arg_idx));
}
#endif
expression *test_parser::parse_binary_primary(unsigned int start, unsigned int end) {
/* We need three arguments */
for (unsigned int idx = start; idx < start + 3; idx++) {
if (idx >= end) {
return error(L"Missing argument at index %u", idx);
}
}
/* All our binary primaries are infix, so the operator is at start + 1. */
const token_info_t *info = token_for_string(arg(start + 1));
if (! (info->flags & BINARY_PRIMARY))
return NULL;
return new binary_primary(info->tok, range_t(start, start + 3), arg(start), arg(start + 2));
}
expression *test_parser::parse_parenthentical(unsigned int start, unsigned int end) {
/* We need at least three arguments: open paren, argument, close paren */
if (start + 3 >= end)
return NULL;
/* Must start with an open expression */
const token_info_t *open_paren = token_for_string(arg(start));
if (open_paren->tok != test_paren_open)
return NULL;
/* Parse a subexpression */
expression *subexr_ptr = parse_expression(start + 1, end);
if (! subexr_ptr)
return NULL;
expr_ref_t subexpr(subexr_ptr);
/* Parse a close paren */
unsigned close_index = subexpr->range.end;
assert(close_index <= end);
if (close_index == end) {
return error(L"Missing close paren at index %u", close_index);
}
const token_info_t *close_paren = token_for_string(arg(close_index));
if (close_paren->tok != test_paren_close) {
return error(L"Expected close paren at index %u", close_index);
}
/* Success */
return new parenthetical_expression(test_paren_open, range_t(start, close_index+1), subexpr);
}
expression *test_parser::parse_primary(unsigned int start, unsigned int end) {
if (start >= end) {
return error(L"Missing argument at index %u", start);
}
expression *expr = NULL;
if (! expr) expr = parse_parenthentical(start, end);
if (! expr) expr = parse_unary_primary(start, end);
if (! expr) expr = parse_binary_primary(start, end);
if (! expr) expr = parse_just_a_string(start, end);
return expr;
}
expression *test_parser::parse_expression(unsigned int start, unsigned int end) {
if (start >= end) {
return error(L"Missing argument at index %u", start);
}
return parse_combining_expression(start, end);
}
expression *test_parser::parse_args(const wcstring_list_t &args, wcstring &err) {
/* Empty list and one-arg list should be handled by caller */
assert(args.size() > 1);
test_parser parser(args);
expression *result = parser.parse_expression(0, (unsigned int)args.size());
/* Handle errors */
bool errored = false;
for (size_t i = 0; i < parser.errors.size(); i++) {
err.append(L"test: ");
err.append(parser.errors.at(i));
err.push_back(L'\n');
errored = true;
// For now we only show the first error
break;
}
if (! errored && result) {
/* It's also an error if there are any unused arguments. This is not detected by parse_expression() */
assert(result->range.end <= args.size());
if (result->range.end < args.size()) {
append_format(err, L"test: unexpected argument at index %lu: '%ls'\n", (unsigned long)result->range.end, args.at(result->range.end).c_str());
delete result;
result = NULL;
errored = true;
}
}
return result;
}
bool unary_primary::evaluate(wcstring_list_t &errors) {
return unary_primary_evaluate(token, arg, errors);
}
bool binary_primary::evaluate(wcstring_list_t &errors) {
return binary_primary_evaluate(token, arg_left, arg_right, errors);
}
bool unary_operator::evaluate(wcstring_list_t &errors) {
switch (token) {
case test_bang:
assert(subject.get());
return ! subject->evaluate(errors);
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
}
}
bool combining_expression::evaluate(wcstring_list_t &errors) {
switch (token) {
case test_combine_and:
case test_combine_or:
{
/* One-element case */
if (subjects.size() == 1)
return subjects.at(0)->evaluate(errors);
/* Evaluate our lists, remembering that AND has higher precedence than OR. We can visualize this as a sequence of OR expressions of AND expressions. */
assert(combiners.size() + 1 == subjects.size());
assert(! subjects.empty());
size_t idx = 0, max = subjects.size();
bool or_result = false;
while (idx < max) {
if (or_result) {
/* Short circuit */
break;
}
/* Evaluate a stream of AND starting at given subject index. It may only have one element. */
bool and_result = true;
for (; idx < max; idx++) {
/* Evaluate it, short-circuiting */
and_result = and_result && subjects.at(idx)->evaluate(errors);
/* If the combiner at this index (which corresponding to how we combine with the next subject) is not AND, then exit the loop */
if (idx + 1 < max && combiners.at(idx) != test_combine_and) {
idx++;
break;
}
}
/* OR it in */
or_result = or_result || and_result;
}
return or_result;
}
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return BUILTIN_TEST_FAIL;
}
}
bool parenthetical_expression::evaluate(wcstring_list_t &errors) {
return contents->evaluate(errors);
}
/* IEEE 1003.1 says nothing about what it means for two strings to be "algebraically equal". For example, should we interpret 0x10 as 0, 10, or 16? Here we use only base 10 and use wcstoll, which allows for leading + and -, and leading whitespace. This matches bash. */
static bool parse_number(const wcstring &arg, long long *out) {
const wchar_t *str = arg.c_str();
wchar_t *endptr = NULL;
*out = wcstoll(str, &endptr, 10);
return endptr && *endptr == L'\0';
}
static bool binary_primary_evaluate(test_expressions::token_t token, const wcstring &left, const wcstring &right, wcstring_list_t &errors) {
using namespace test_expressions;
long long left_num, right_num;
switch (token) {
case test_string_equal:
return left == right;
case test_string_not_equal:
return left != right;
case test_number_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num == right_num;
case test_number_not_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num != right_num;
case test_number_greater:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num > right_num;
case test_number_greater_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num >= right_num;
case test_number_lesser:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num < right_num;
case test_number_lesser_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num <= right_num;
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
}
}
static bool unary_primary_evaluate(test_expressions::token_t token, const wcstring &arg, wcstring_list_t &errors) {
using namespace test_expressions;
struct stat buf;
long long num;
switch (token) {
case test_filetype_b: // "-b", for block special files
return !wstat(arg, &buf) && S_ISBLK(buf.st_mode);
case test_filetype_c: // "-c" for character special files
return !wstat(arg, &buf) && S_ISCHR(buf.st_mode);
case test_filetype_d: // "-d" for directories
return !wstat(arg, &buf) && S_ISDIR(buf.st_mode);
case test_filetype_e: // "-e" for files that exist
return !wstat(arg, &buf);
case test_filetype_f: // "-f" for for regular files
return !wstat(arg, &buf) && S_ISREG(buf.st_mode);
case test_filetype_g: // "-g" for set-group-id
return !wstat(arg, &buf) && (S_ISGID & buf.st_mode);
case test_filetype_h: // "-h" for symbolic links
case test_filetype_L: // "-L", same as -h
return !lwstat(arg, &buf) && S_ISLNK(buf.st_mode);
case test_filetype_p: // "-p", for FIFO
return !wstat(arg, &buf) && S_ISFIFO(buf.st_mode);
case test_filetype_S: // "-S", socket
return !wstat(arg, &buf) && S_ISSOCK(buf.st_mode);
case test_filesize_s: // "-s", size greater than zero
return !wstat(arg, &buf) && buf.st_size > 0;
case test_filedesc_t: // "-t", whether the fd is associated with a terminal
return parse_number(arg, &num) && num == (int)num && isatty((int)num);
case test_fileperm_r: // "-r", read permission
return !waccess(arg, R_OK);
case test_fileperm_u: // "-u", whether file is setuid
return !wstat(arg, &buf) && (S_ISUID & buf.st_mode);
case test_fileperm_w: // "-w", whether file write permission is allowed
return !waccess(arg, W_OK);
case test_fileperm_x: // "-x", whether file execute/search is allowed
return !waccess(arg, X_OK);
case test_string_n: // "-n", non-empty string
return ! arg.empty();
case test_string_z: // "-z", true if length of string is 0
return arg.empty();
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
}
}
};
/*
* Evaluate a conditional expression given the arguments.
* If fromtest is set, the caller is the test or [ builtin;
* with the pointer giving the name of the command.
* for POSIX conformance this supports a more limited range
* of functionality.
*
* Return status is the final shell status, i.e. 0 for true,
* 1 for false and 2 for error.
*/
int builtin_test( parser_t &parser, wchar_t **argv )
{
using namespace test_expressions;
/* The first argument should be the name of the command ('test') */
if (! argv[0])
return BUILTIN_TEST_FAIL;
size_t argc = 0;
while (argv[argc + 1])
argc++;
const wcstring_list_t args(argv + 1, argv + 1 + argc);
if (argc == 0) {
// Per 1003.1, exit false
return BUILTIN_TEST_FAIL;
} else if (argc == 1) {
// Per 1003.1, exit true if the arg is non-empty
return args.at(0).empty() ? BUILTIN_TEST_FAIL : BUILTIN_TEST_SUCCESS;
} else {
// Try parsing. If expr is not nil, we are responsible for deleting it.
wcstring err;
expression *expr = test_parser::parse_args(args, err);
if (! expr) {
#if 0
printf("Oops! test was given args:\n");
for (size_t i=0; i < argc; i++) {
printf("\t%ls\n", args.at(i).c_str());
}
printf("and returned parse error: %ls\n", err.c_str());
#endif
builtin_show_error(err);
return BUILTIN_TEST_FAIL;
} else {
wcstring_list_t eval_errors;
bool result = expr->evaluate(eval_errors);
if (! eval_errors.empty()) {
printf("test returned eval errors:\n");
for (size_t i=0; i < eval_errors.size(); i++) {
printf("\t%ls\n", eval_errors.at(i).c_str());
}
}
delete expr;
return result ? BUILTIN_TEST_SUCCESS : BUILTIN_TEST_FAIL;
}
}
return 1;
}

View File

@@ -49,7 +49,7 @@ struct resource_t
/**
Array of resource_t structs, describing all known resource types.
*/
const static struct resource_t resource_arr[] =
static const struct resource_t resource_arr[] =
{
{
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
@@ -144,9 +144,9 @@ static void print( int resource, int hard )
rlim_t l = get( resource, hard );
if( l == RLIM_INFINITY )
sb_append( sb_out, L"unlimited\n" );
stdout_buffer.append( L"unlimited\n" );
else
sb_printf( sb_out, L"%d\n", l / get_multiplier( resource ) );
append_format(stdout_buffer, L"%d\n", l / get_multiplier( resource ) );
}
@@ -170,9 +170,9 @@ static void print_all( int hard )
getrlimit( resource_arr[i].resource, &ls );
l = hard ? ls.rlim_max:ls.rlim_cur;
wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
const wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
sb_printf( sb_out,
append_format(stdout_buffer,
L"%-*ls %10ls-%lc) ",
w,
resource_arr[i].desc,
@@ -181,11 +181,11 @@ static void print_all( int hard )
if( l == RLIM_INFINITY )
{
sb_append( sb_out, L"unlimited\n" );
stdout_buffer.append( L"unlimited\n" );
}
else
{
sb_printf( sb_out, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
append_format(stdout_buffer, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
}
}
@@ -240,7 +240,7 @@ static int set( int resource, int hard, int soft, rlim_t value )
if( setrlimit( resource, &ls ) )
{
if( errno == EPERM )
sb_printf( sb_err, L"ulimit: Permission denied when changing resource of type '%ls'\n", get_desc( resource ) );
append_format(stderr_buffer, L"ulimit: Permission denied when changing resource of type '%ls'\n", get_desc( resource ) );
else
builtin_wperror( L"ulimit" );
return 1;
@@ -252,7 +252,7 @@ static int set( int resource, int hard, int soft, rlim_t value )
The ulimit builtin, used for setting resource limits. Defined in
builtin_ulimit.c.
*/
static int builtin_ulimit( wchar_t ** argv )
static int builtin_ulimit( parser_t &parser, wchar_t ** argv )
{
int hard=0;
int soft=0;
@@ -266,7 +266,7 @@ static int builtin_ulimit( wchar_t ** argv )
while( 1 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -347,11 +347,11 @@ static int builtin_ulimit( wchar_t ** argv )
case 0:
if(long_options[opt_index].flag != 0)
break;
sb_printf( sb_err,
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
@@ -415,11 +415,11 @@ static int builtin_ulimit( wchar_t ** argv )
#endif
case L'h':
builtin_print_help( argv[0], sb_out );
builtin_print_help( parser, argv[0], stdout_buffer );
return 0;
case L'?':
builtin_unknown_option( argv[0], argv[woptind-1] );
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
return 1;
}
}
@@ -432,11 +432,9 @@ static int builtin_ulimit( wchar_t ** argv )
}
else
{
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );
builtin_print_help( argv[0], sb_err );
stderr_buffer.append(argv[0]);
stderr_buffer.append(L": Too many arguments\n");
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
@@ -488,11 +486,11 @@ static int builtin_ulimit( wchar_t ** argv )
new_limit = wcstol( argv[woptind], &end, 10 );
if( errno || *end )
{
sb_printf( sb_err,
append_format(stderr_buffer,
L"%ls: Invalid limit '%ls'\n",
argv[0],
argv[woptind] );
builtin_print_help( argv[0], sb_err );
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}
new_limit *= get_multiplier( what );
@@ -503,11 +501,9 @@ static int builtin_ulimit( wchar_t ** argv )
default:
{
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
(void *)0 );
builtin_print_help( argv[0], sb_err );
stderr_buffer.append(argv[0]);
stderr_buffer.append(L": Too many arguments\n");
builtin_print_help( parser, argv[0], stderr_buffer );
return 1;
}

266
color.cpp Normal file
View File

@@ -0,0 +1,266 @@
/** \file color.cpp Color class implementation
*/
#include "color.h"
#include "fallback.h"
bool rgb_color_t::try_parse_special(const wcstring &special) {
bzero(&data, sizeof data);
const wchar_t *name = special.c_str();
if (! wcscasecmp(name, L"normal")) {
this->type = type_normal;
} else if (! wcscasecmp(name, L"reset")) {
this->type = type_reset;
} else if (! wcscasecmp(name, L"ignore")) {
this->type = type_ignore;
} else {
this->type = type_none;
}
return this->type != type_none;
}
static int parse_hex_digit(wchar_t x) {
switch (x) {
case L'0': return 0x0;
case L'1': return 0x1;
case L'2': return 0x2;
case L'3': return 0x3;
case L'4': return 0x4;
case L'5': return 0x5;
case L'6': return 0x6;
case L'7': return 0x7;
case L'8': return 0x8;
case L'9': return 0x9;
case L'a':case L'A': return 0xA;
case L'b':case L'B': return 0xB;
case L'c':case L'C': return 0xC;
case L'd':case L'D': return 0xD;
case L'e':case L'E': return 0xE;
case L'f':case L'F': return 0xF;
default: return -1;
}
}
static unsigned long squared_difference(long p1, long p2)
{
unsigned long diff = (unsigned long)labs(p1 - p2);
return diff * diff;
}
static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *colors, size_t color_count) {
long r = rgb[0], g = rgb[1], b = rgb[2];
unsigned long best_distance = (unsigned long)(-1);
unsigned char best_index = (unsigned char)(-1);
for (unsigned char idx = 0; idx < color_count; idx++) {
uint32_t color = colors[idx];
long test_r = (color >> 16) & 0xFF, test_g = (color >> 8) & 0xFF, test_b = (color >> 0) & 0xFF;
unsigned long distance = squared_difference(r, test_r) + squared_difference(g, test_g) + squared_difference(b, test_b);
if (distance <= best_distance) {
best_index = idx;
best_distance = distance;
}
}
return best_index;
}
bool rgb_color_t::try_parse_rgb(const wcstring &name) {
bzero(&data, sizeof data);
/* We support the following style of rgb formats (case insensitive):
#FA3
#F3A035
FA3
F3A035
*/
size_t digit_idx = 0, len = name.size();
/* Skip any leading # */
if (len > 0 && name.at(0) == L'#')
digit_idx++;
bool success = false;
size_t i;
if (len - digit_idx == 3) {
// type FA3
for (i=0; i < 3; i++) {
int val = parse_hex_digit(name.at(digit_idx++));
if (val < 0) break;
data.rgb[i] = val*16+val;
}
success = (i == 3);
} else if (len - digit_idx == 6) {
// type F3A035
for (i=0; i < 3; i++) {
int hi = parse_hex_digit(name.at(digit_idx++));
int lo = parse_hex_digit(name.at(digit_idx++));
if (lo < 0 || hi < 0) break;
data.rgb[i] = hi*16+lo;
}
success = (i == 3);
}
if (success) {
this->type = type_rgb;
}
return success;
}
struct named_color_t {
const wchar_t * name;
unsigned char idx;
unsigned char rgb[3];
};
static const named_color_t named_colors[11] = {
{L"black", 0, {0, 0, 0}},
{L"red", 1, {0xFF, 0, 0}},
{L"green", 2, {0, 0xFF, 0}},
{L"brown", 3, {0x72, 0x50, 0}},
{L"yellow", 3, {0xFF, 0xFF, 0}},
{L"blue", 4, {0, 0, 0xFF}},
{L"magenta", 5, {0xFF, 0, 0xFF}},
{L"purple", 5, {0xFF, 0, 0xFF}},
{L"cyan", 6, {0, 0xFF, 0xFF}},
{L"white", 7, {0xFF, 0xFF, 0xFF}},
{L"normal", 8, {0xFF, 0xFF, 0XFF}}
};
bool rgb_color_t::try_parse_named(const wcstring &str) {
bzero(&data, sizeof data);
size_t max = sizeof named_colors / sizeof *named_colors;
for (size_t idx=0; idx < max; idx++) {
if (0 == wcscasecmp(str.c_str(), named_colors[idx].name)) {
data.name_idx = named_colors[idx].idx;
this->type = type_named;
return true;
}
}
return false;
}
static const wchar_t *name_for_color_idx(unsigned char idx) {
size_t max = sizeof named_colors / sizeof *named_colors;
for (size_t i=0; i < max; i++) {
if (named_colors[i].idx == idx) {
return named_colors[i].name;
}
}
return L"unknown";
}
rgb_color_t::rgb_color_t(unsigned char t, unsigned char i) : type(t), flags(), data() {
data.name_idx = i;
}
rgb_color_t rgb_color_t::normal() { return rgb_color_t(type_normal); }
rgb_color_t rgb_color_t::reset() { return rgb_color_t(type_reset); }
rgb_color_t rgb_color_t::ignore() { return rgb_color_t(type_ignore); }
rgb_color_t rgb_color_t::none() { return rgb_color_t(type_none); }
rgb_color_t rgb_color_t::white() { return rgb_color_t(type_named, 7); }
rgb_color_t rgb_color_t::black() { return rgb_color_t(type_named, 0); }
static unsigned char term8_color_for_rgb(const unsigned char rgb[3]) {
const uint32_t kColors[] = {
0x000000, //Black
0xFF0000, //Red
0x00FF00, //Green
0xFFFF00, //Yellow
0x0000FF, //Blue
0xFF00FF, //Magenta
0x00FFFF, //Cyan
0xFFFFFF, //White
};
return convert_color(rgb, kColors, sizeof kColors / sizeof *kColors);
}
static unsigned char term256_color_for_rgb(const unsigned char rgb[3]) {
const uint32_t kColors[240] = {
0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f,
0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f, 0x008787, 0x0087af,
0x0087d7, 0x0087ff, 0x00af00, 0x00af5f, 0x00af87, 0x00afaf, 0x00afd7, 0x00afff,
0x00d700, 0x00d75f, 0x00d787, 0x00d7af, 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f,
0x00ff87, 0x00ffaf, 0x00ffd7, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af,
0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f, 0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff,
0x5f8700, 0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff, 0x5faf00, 0x5faf5f,
0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af,
0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87, 0x5fffaf, 0x5fffd7, 0x5fffff,
0x870000, 0x87005f, 0x870087, 0x8700af, 0x8700d7, 0x8700ff, 0x875f00, 0x875f5f,
0x875f87, 0x875faf, 0x875fd7, 0x875fff, 0x878700, 0x87875f, 0x878787, 0x8787af,
0x8787d7, 0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf, 0x87afd7, 0x87afff,
0x87d700, 0x87d75f, 0x87d787, 0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f,
0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af,
0xaf00d7, 0xaf00ff, 0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7, 0xaf5fff,
0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af, 0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f,
0xafaf87, 0xafafaf, 0xafafd7, 0xafafff, 0xafd700, 0xafd75f, 0xafd787, 0xafd7af,
0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff,
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f,
0xd75f87, 0xd75faf, 0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af,
0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f, 0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff,
0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff, 0xd7ff00, 0xd7ff5f,
0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fd7, 0xff5fff,
0xff8700, 0xff875f, 0xff8787, 0xff87af, 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f,
0xffaf87, 0xffafaf, 0xffafd7, 0xffafff, 0xffd700, 0xffd75f, 0xffd787, 0xffd7af,
0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffd7, 0xffffff,
0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e,
0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
};
return 16 + convert_color(rgb, kColors, sizeof kColors / sizeof *kColors);
}
unsigned char rgb_color_t::to_term256_index() const {
assert(type == type_rgb);
return term256_color_for_rgb(data.rgb);
}
unsigned char rgb_color_t::to_name_index() const {
assert(type == type_named || type == type_rgb);
if (type == type_named) {
return data.name_idx;
} else if (type == type_rgb) {
return term8_color_for_rgb(data.rgb);
} else {
/* This is an error */
return (unsigned char)(-1);
}
}
void rgb_color_t::parse(const wcstring &str) {
bool success = false;
if (! success) success = try_parse_special(str);
if (! success) success = try_parse_named(str);
if (! success) success = try_parse_rgb(str);
if (! success) {
bzero(this->data.rgb, sizeof this->data.rgb);
this->type = type_none;
}
}
rgb_color_t::rgb_color_t(const wcstring &str) {
this->parse(str);
}
rgb_color_t::rgb_color_t(const std::string &str) {
this->parse(str2wcstring(str));
}
wcstring rgb_color_t::description() const {
switch (type) {
case type_none:
return L"none";
case type_named:
return format_string(L"named(%d: %ls)", (int)data.name_idx, name_for_color_idx(data.name_idx));
case type_rgb:
return format_string(L"rgb(0x%02x%02x%02x)", data.rgb[0], data.rgb[1], data.rgb[2]);
case type_reset:
return L"reset";
case type_normal:
return L"normal";
case type_ignore:
return L"ignore";
default:
abort();
return L"";
}
}

133
color.h Normal file
View File

@@ -0,0 +1,133 @@
/** \file color.h Color class.
*/
#ifndef FISH_COLOR_H
#define FISH_COLOR_H
#include <stdint.h>
#include <cstddef>
#include "config.h"
#include "common.h"
/* A type that represents a color. We work hard to keep it at a size of 4 bytes. */
class rgb_color_t {
/* Types */
enum {
type_none,
type_named,
type_rgb,
type_normal,
type_reset,
type_ignore
};
unsigned char type:4;
/* Flags */
enum {
flag_bold = 1 << 0,
flag_underline = 1 << 1
};
unsigned char flags:4;
union {
unsigned char name_idx; //0-10
unsigned char rgb[3];
} data;
/** Try parsing a special color name like "normal" */
bool try_parse_special(const wcstring &str);
/** Try parsing an rgb color like "#F0A030" */
bool try_parse_rgb(const wcstring &str);
/** Try parsing an explicit color name like "magenta" */
bool try_parse_named(const wcstring &str);
/* Parsing entry point */
void parse(const wcstring &str);
/** Private constructor */
explicit rgb_color_t(unsigned char t, unsigned char i=0);
public:
/** Default constructor of type none */
explicit rgb_color_t() : type(type_none), flags(), data() {}
/** Parse a color from a string */
explicit rgb_color_t(const wcstring &str);
explicit rgb_color_t(const std::string &str);
/** Returns white */
static rgb_color_t white();
/** Returns black */
static rgb_color_t black();
/** Returns the reset special color */
static rgb_color_t reset();
/** Returns the normal special color */
static rgb_color_t normal();
/** Returns the ignore special color */
static rgb_color_t ignore();
/** Returns the none special color */
static rgb_color_t none();
/** Returns whether the color is the ignore special color */
bool is_ignore(void) const { return type == type_ignore; }
/** Returns whether the color is the normal special color */
bool is_normal(void) const { return type == type_normal; }
/** Returns whether the color is the reset special color */
bool is_reset(void) const { return type == type_reset; }
/** Returns whether the color is the none special color */
bool is_none(void) const { return type == type_none; }
/** Returns whether the color is a named color (like "magenta") */
bool is_named(void) const { return type == type_named; }
/** Returns whether the color is specified via RGB components */
bool is_rgb(void) const { return type == type_rgb; }
/** Returns whether the color is special, that is, not rgb or named */
bool is_special(void) const { return type != type_named && type != type_rgb; }
/** Returns a description of the color */
wcstring description() const;
/** Returns the name index for the given color. Requires that the color be named or RGB. */
unsigned char to_name_index() const;
/** Returns the term256 index for the given color. Requires that the color be named or RGB. */
unsigned char to_term256_index() const;
/** Returns whether the color is bold */
bool is_bold() const { return flags & flag_bold; }
/** Set whether the color is bold */
void set_bold(bool x) { if (x) flags |= flag_bold; else flags &= ~flag_bold; }
/** Returns whether the color is underlined */
bool is_underline() const { return !! (flags & flag_underline); }
/** Set whether the color is underlined */
void set_underline(bool x) { if (x) flags |= flag_underline; else flags &= ~flag_underline; }
/** Compare two colors for equality */
bool operator==(const rgb_color_t &other) const {
return type == other.type && ! memcmp(&data, &other.data, sizeof data);
}
/** Compare two colors for inequality */
bool operator!=(const rgb_color_t &other) const {
return !(*this == other);
}
};
#endif

1802
common.c

File diff suppressed because it is too large Load Diff

2035
common.cpp Normal file

File diff suppressed because it is too large Load Diff

481
common.h
View File

@@ -12,9 +12,22 @@
#include <stdio.h>
#include <wchar.h>
#include <termios.h>
#include <string>
#include <sstream>
#include <vector>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include "util.h"
class completion_t;
/* Common string type */
typedef std::wstring wcstring;
typedef std::vector<wcstring> wcstring_list_t;
/**
Maximum number of bytes used by a single utf-8 character
*/
@@ -40,24 +53,36 @@
*/
#define BYTE_MAX 0xffu
/*
Escape special fish syntax characters liek the semicolon
/**
Escape special fish syntax characters like the semicolon
*/
#define UNESCAPE_SPECIAL 1
/*
/**
Allow incomplete escape sequences
*/
#define UNESCAPE_INCOMPLETE 2
/**
Escape all characters, including magic characters like the semicolon
*/
#define ESCAPE_ALL 1
/**
Do not try to use 'simplified' quoted escapes, and do not use empty quotes as the empty string
*/
#define ESCAPE_NO_QUOTED 2
/* Flags for the escape() and escape_string() functions */
enum {
/** Escape all characters, including magic characters like the semicolon */
ESCAPE_ALL = 1 << 0,
/** Do not try to use 'simplified' quoted escapes, and do not use empty quotes as the empty string */
ESCAPE_NO_QUOTED = 1 << 1,
/** Do not escape tildes */
ESCAPE_NO_TILDE = 1 << 2
};
typedef unsigned int escape_flags_t;
/**
Helper macro for errors
*/
#define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { int err = errno; fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", #a, __LINE__, __FILE__, err, strerror(err)); abort(); }} while (0)
/** Exits without invoking destructors (via _exit), useful for code after fork. */
void exit_without_destructors(int code) __attribute__ ((noreturn));
/**
Save the shell mode on startup so we can restore them on exit
@@ -85,7 +110,7 @@ extern char *profile;
Name of the current program. Should be set at startup. Used by the
debug function.
*/
extern wchar_t *program_name;
extern const wchar_t *program_name;
/**
This macro is used to check that an input argument is not null. It
@@ -97,7 +122,7 @@ extern wchar_t *program_name;
if( !(arg) ) \
{ \
debug( 0, \
_( L"function %s called with null value for argument %s. " ), \
"function %s called with null value for argument %s. ", \
__func__, \
#arg ); \
bugreport(); \
@@ -108,13 +133,13 @@ extern wchar_t *program_name;
/**
Pause for input, then exit the program. If supported, print a backtrace first.
*/
#define FATAL_EXIT() \
{ \
char c; \
show_stackframe(); \
read( 0, &c, 1 ); \
exit( 1 ); \
} \
#define FATAL_EXIT() \
{ \
char exit_read_buff; \
show_stackframe(); \
read( 0, &exit_read_buff, 1 ); \
exit_without_destructors( 1 ); \
} \
/**
@@ -123,8 +148,8 @@ extern wchar_t *program_name;
#define DIE_MEM() \
{ \
fwprintf( stderr, \
L"fish: Out of memory on line %d of file %s, shutting down fish\n", \
__LINE__, \
L"fish: Out of memory on line %ld of file %s, shutting down fish\n", \
(long)__LINE__, \
__FILE__ ); \
FATAL_EXIT(); \
}
@@ -137,7 +162,7 @@ extern wchar_t *program_name;
if( signal_is_blocked() ) \
{ \
debug( 0, \
_( L"function %s called while blocking signals. " ), \
"function %s called while blocking signals. ", \
__func__); \
bugreport(); \
show_stackframe(); \
@@ -147,7 +172,7 @@ extern wchar_t *program_name;
/**
Shorthand for wgettext call
*/
#define _(wstr) wgettext(wstr)
#define _(wstr) wgettext((const wchar_t *)wstr)
/**
Noop, used to tell xgettext that a string should be translated,
@@ -155,39 +180,27 @@ extern wchar_t *program_name;
*/
#define N_(wstr) wstr
#define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
/**
Check if the specified string element is a part of the specified string list
*/
#define contains( str,... ) contains_internal( str, __VA_ARGS__, NULL )
/*
/**
Print a stack trace to stderr
*/
void show_stackframe();
/**
Take an array_list_t containing wide strings and converts them to a
single null-terminated wchar_t **. The array is allocated using
malloc, and needs to be fred's by the caller.
*/
wchar_t **list_to_char_arr( array_list_t *l );
/**
Read a line from the stream f into the buffer buff of length len. If
buff is to small, it will be reallocated, and both buff and len will
be updated to reflect this. Returns the number of bytes read or -1
on failiure.
Read a line from the stream f into the string. Returns
the number of bytes read or -1 on failiure.
If the carriage return character is encountered, it is
ignored. fgetws() considers the line to end if reading the file
results in either a newline (L'\n') character, the null (L'\\0')
character or the end of file (WEOF) character.
*/
int fgetws2( wchar_t **buff, int *len, FILE *f );
/**
Sorts an array_list of wide strings according to the
wcsfilecmp-function from the util library
*/
void sort_list( array_list_t *comp );
int fgetws2(wcstring *s, FILE *f);
/**
Returns a newly allocated wide character string equivalent of the
@@ -198,6 +211,16 @@ void sort_list( array_list_t *comp );
*/
wchar_t *str2wcs( const char *in );
/**
Returns a newly allocated wide character string equivalent of the
specified multibyte character string
This function encodes illegal character sequences in a reversible
way using the private use area.
*/
wcstring str2wcstring( const char *in );
wcstring str2wcstring( const std::string &in );
/**
Converts the narrow character string \c in into it's wide
equivalent, stored in \c out. \c out must have enough space to fit
@@ -216,6 +239,35 @@ wchar_t *str2wcs_internal( const char *in, wchar_t *out );
way using the private use area.
*/
char *wcs2str( const wchar_t *in );
std::string wcs2string(const wcstring &input);
/** Test if a string prefixes another. Returns true if a is a prefix of b */
bool string_prefixes_string(const wcstring &proposed_prefix, const wcstring &value);
bool string_prefixes_string(const wchar_t *proposed_prefix, const wcstring &value);
/** Test if a string is a suffix of another */
bool string_suffixes_string(const wcstring &proposed_suffix, const wcstring &value);
bool string_suffixes_string(const wchar_t *proposed_suffix, const wcstring &value);
/** Test if a string prefixes another without regard to case. Returns true if a is a prefix of b */
bool string_prefixes_string_case_insensitive(const wcstring &proposed_prefix, const wcstring &value);
/** Test if a list contains a string using a linear search. */
bool list_contains_string(const wcstring_list_t &list, const wcstring &str);
void assert_is_main_thread(const char *who);
#define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)
#define ASSERT_IS_MAIN_THREAD() ASSERT_IS_MAIN_THREAD_TRAMPOLINE(__FUNCTION__)
void assert_is_background_thread(const char *who);
#define ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(x) assert_is_background_thread(x)
#define ASSERT_IS_BACKGROUND_THREAD() ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(__FUNCTION__)
/* Useful macro for asserting that a lock is locked. This doesn't check whether this thread locked it, which it would be nice if it did, but here it is anyways. */
void assert_is_locked(void *mutex, const char *who, const char *caller);
#define ASSERT_IS_LOCKED(x) assert_is_locked((void *)(&x), #x, __FUNCTION__)
/**
Converts the wide character string \c in into it's narrow
@@ -227,28 +279,244 @@ char *wcs2str( const wchar_t *in );
*/
char *wcs2str_internal( const wchar_t *in, char *out );
/** Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer. */
wcstring format_size(long long sz);
/** Version of format_size that does not allocate memory. */
void format_size_safe(char buff[128], unsigned long long sz);
/** Our crappier versions of debug which is guaranteed to not allocate any memory, or do anything other than call write(). This is useful after a call to fork() with threads. */
void debug_safe(int level, const char *msg, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL, const char *param5 = NULL, const char *param6 = NULL, const char *param7 = NULL, const char *param8 = NULL, const char *param9 = NULL, const char *param10 = NULL, const char *param11 = NULL, const char *param12 = NULL);
/** Writes out a long safely */
void format_long_safe(char buff[128], long val);
void format_long_safe(wchar_t buff[128], long val);
template<typename T>
T from_string(const wcstring &x) {
T result;
std::wstringstream stream(x);
stream >> result;
return result;
}
template<typename T>
T from_string(const std::string &x) {
T result = T();
std::stringstream stream(x);
stream >> result;
return result;
}
template<typename T>
wcstring to_string(const T &x) {
std::wstringstream stream;
stream << x;
return stream.str();
}
/* wstringstream is a huge memory pig. Let's provide some specializations where we can. */
template<>
inline wcstring to_string(const long &x) {
wchar_t buff[128];
format_long_safe(buff, x);
return wcstring(buff);
}
template<>
inline bool from_string(const std::string &x) {
return ! x.empty() && strchr("YTyt1", x.at(0));
}
template<>
inline bool from_string(const wcstring &x) {
return ! x.empty() && wcschr(L"YTyt1", x.at(0));
}
template<>
inline wcstring to_string(const int &x) {
return to_string(static_cast<long>(x));
}
/* Helper class for managing a null-terminated array of null-terminated strings (of some char type) */
template <typename CharType_t>
class null_terminated_array_t {
CharType_t **array;
typedef std::basic_string<CharType_t> string_t;
typedef std::vector<string_t> string_list_t;
void swap(null_terminated_array_t<CharType_t> &him) { std::swap(array, him.array); }
/* Silly function to get the length of a null terminated array of...something */
template <typename T>
static size_t count_not_null(const T *arr) {
size_t len;
for (len=0; arr[len] != T(0); len++)
;
return len;
}
size_t size() const {
return count_not_null(array);
}
void free(void) {
if (array != NULL) {
for (size_t i = 0; array[i] != NULL; i++) {
delete [] array[i];
}
delete [] array;
array = NULL;
}
}
public:
null_terminated_array_t() : array(NULL) { }
null_terminated_array_t(const string_list_t &argv) : array(NULL) { this->set(argv); }
~null_terminated_array_t() { this->free(); }
/** operator=. Notice the pass-by-value parameter. */
null_terminated_array_t& operator=(null_terminated_array_t rhs) {
if (this != &rhs)
this->swap(rhs);
return *this;
}
/* Copy constructor. */
null_terminated_array_t(const null_terminated_array_t &him) : array(NULL) {
this->set(him.array);
}
void set(const string_list_t &argv) {
/* Get rid of the old argv */
this->free();
/* Allocate our null-terminated array of null-terminated strings */
size_t i, count = argv.size();
this->array = new CharType_t * [count + 1];
for (i=0; i < count; i++) {
const string_t &str = argv.at(i);
this->array[i] = new CharType_t [1 + str.size()];
std::copy(str.begin(), str.end(), this->array[i]);
this->array[i][str.size()] = CharType_t(0);
}
this->array[count] = NULL;
}
void set(const CharType_t * const *new_array) {
if (new_array == array)
return;
/* Get rid of the old argv */
this->free();
/* Copy the new one */
if (new_array) {
size_t i, count = count_not_null(new_array);
this->array = new CharType_t * [count + 1];
for (i=0; i < count; i++) {
size_t len = count_not_null(new_array[i]);
this->array[i] = new CharType_t [1 + len];
std::copy(new_array[i], new_array[i] + len, this->array[i]);
this->array[i][len] = CharType_t(0);
}
this->array[count] = NULL;
}
}
CharType_t **get() { return array; }
const CharType_t * const *get() const { return array; }
string_list_t to_list() const {
string_list_t lst;
if (array != NULL) {
size_t count = this->size();
lst.reserve(count);
lst.insert(lst.end(), array, array + count);
}
return lst;
}
};
/* Helper function to convert from a null_terminated_array_t<wchar_t> to a null_terminated_array_t<char_t> */
null_terminated_array_t<char> convert_wide_array_to_narrow(const null_terminated_array_t<wchar_t> &arr);
/* Helper class to cache a narrow version of a wcstring in a malloc'd buffer, so that we can read it after fork() */
class narrow_string_rep_t {
private:
const char *str;
/* No copying */
narrow_string_rep_t &operator=(const narrow_string_rep_t &);
narrow_string_rep_t(const narrow_string_rep_t &x);
public:
~narrow_string_rep_t() {
free((void *)str);
}
narrow_string_rep_t() : str(NULL) {}
void set(const wcstring &s) {
free((void *)str);
str = wcs2str(s.c_str());
}
const char *get() const {
return str;
}
};
bool is_forked_child();
/* Basic scoped lock class */
class scoped_lock {
pthread_mutex_t *lock_obj;
bool locked;
/* No copying */
scoped_lock &operator=(const scoped_lock &);
scoped_lock(const scoped_lock &);
public:
void lock(void);
void unlock(void);
scoped_lock(pthread_mutex_t &mutex);
~scoped_lock();
};
/* Wrapper around wcstok */
class wcstokenizer {
wchar_t *buffer, *str, *state;
const wcstring sep;
/* No copying */
wcstokenizer &operator=(const wcstokenizer &);
wcstokenizer(const wcstokenizer &);
public:
wcstokenizer(const wcstring &s, const wcstring &separator);
bool next(wcstring &result);
~wcstokenizer();
};
/**
Appends a path component, with a / if necessary
*/
void append_path_component(wcstring &path, const wcstring &component);
wcstring format_string(const wchar_t *format, ...);
wcstring vformat_string(const wchar_t *format, va_list va_orig);
void append_format(wcstring &str, const wchar_t *format, ...);
/**
Returns a newly allocated wide character string array equivalent of
the specified multibyte character string array
*/
char **wcsv2strv( const wchar_t **in );
/**
Returns a newly allocated multibyte character string array equivalent of the specified wide character string array
*/
wchar_t **strv2wcsv( const char **in );
/**
Returns a newly allocated concatenation of the specified wide
character strings. The last argument must be a null pointer.
*/
__sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
/**
Test if the given string is a valid variable name
*/
char **wcsv2strv( const wchar_t * const *in );
/**
Test if the given string is a valid variable name.
@@ -265,7 +533,7 @@ wchar_t *wcsvarname( const wchar_t *str );
\return null if this is a valid name, and a pointer to the first invalid character otherwise
*/
wchar_t *wcsfuncname( const wchar_t *str );
const wchar_t *wcsfuncname( const wchar_t *str );
/**
Test if the given string is valid in a variable name
@@ -306,7 +574,7 @@ void error_reset();
the user is using a Unicode character set, and if so, use the
unicode ellipsis character as ellipsis, instead of '$'.
*/
const wchar_t *wsetlocale( int category, const wchar_t *locale );
wcstring wsetlocale( int category, const wchar_t *locale );
/**
Checks if \c needle is included in the list of strings specified. A warning is printed if needle is zero.
@@ -315,14 +583,27 @@ const wchar_t *wsetlocale( int category, const wchar_t *locale );
\return zero if needle is not found, of if needle is null, non-zero otherwise
*/
__sentinel int contains_internal( const wchar_t *needle, ... );
__sentinel bool contains_internal( const wchar_t *needle, ... );
__sentinel bool contains_internal( const wcstring &needle, ... );
/**
Call read while blocking the SIGCHLD signal. Should only be called
if you _know_ there is data available for reading, or the program
will hang until there is data.
*/
int read_blocked(int fd, void *buf, size_t count);
long read_blocked(int fd, void *buf, size_t count);
/**
Loop a write request while failiure is non-critical. Return -1 and set errno
in case of critical error.
*/
ssize_t write_loop(int fd, const char *buff, size_t count);
/**
Loop a read request while failiure is non-critical. Return -1 and set errno
in case of critical error.
*/
ssize_t read_loop(int fd, void *buff, size_t count);
/**
@@ -343,6 +624,7 @@ int read_blocked(int fd, void *buf, size_t count);
will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that program_name is 'fish'.
*/
void debug( int level, const char *msg, ... );
void debug( int level, const wchar_t *msg, ... );
/**
@@ -354,7 +636,8 @@ void debug( int level, const wchar_t *msg, ... );
\return The escaped string, or 0 if there is not enough memory
*/
wchar_t *escape( const wchar_t *in, int escape_all );
wchar_t *escape( const wchar_t *in, escape_flags_t flags );
wcstring escape_string( const wcstring &in, escape_flags_t flags );
/**
Expand backslashed escapes and substitute them with their unescaped
@@ -370,16 +653,9 @@ wchar_t *escape( const wchar_t *in, int escape_all );
wchar_t *unescape( const wchar_t * in,
int escape_special );
/**
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
milliseconds between polls and timing out after timeout seconds,
thereafter forcibly attempting to obtain the lock if force is non-zero.
Returns 1 on success, 0 on failure.
To release the lock the lockfile must be unlinked.
A unique temporary file named by appending characters to the lockfile name
is used; any pre-existing file of the same name is subject to deletion.
*/
int acquire_lock_file( const char *lockfile, const int timeout, int force );
bool unescape_string( wcstring &str,
int escape_special );
/**
Returns the width of the terminal window, so that not all
@@ -409,17 +685,14 @@ void common_handle_winch( int signal );
Write paragraph of output to the specified stringbuffer, and redo
the linebreaks to fit the current screen.
*/
void write_screen( const wchar_t *msg, string_buffer_t *buff );
void write_screen( const wcstring &msg, wcstring &buff );
/**
Tokenize the specified string into the specified array_list_t.
Each new element is allocated using malloc and must be freed by the
caller.
Tokenize the specified string into the specified wcstring_list_t.
\param val the input string. The contents of this string is not changed.
\param out the list in which to place the elements.
*/
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
void tokenize_variable_array( const wcstring &val, wcstring_list_t &out);
/**
Make sure the specified direcotry exists. If needed, try to create
@@ -427,7 +700,7 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out );
\return 0 if, at the time of function return the directory exists, -1 otherwise.
*/
int create_directory( wchar_t *d );
int create_directory( const wcstring &d );
/**
Print a short message about how to file a bug report to stderr
@@ -435,10 +708,40 @@ int create_directory( wchar_t *d );
void bugreport();
/**
Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer.
*/
void sb_format_size( string_buffer_t *sb,
long long sz );
Return the number of seconds from the UNIX epoch, with subsecond
precision. This function uses the gettimeofday function, and will
have the same precision as that function.
If an error occurs, NAN is returned.
*/
double timef();
/**
Call the following function early in main to set the main thread.
This is our replacement for pthread_main_np().
*/
void set_main_thread();
bool is_main_thread();
/** Configures thread assertions for testing */
void configure_thread_assertions_for_testing();
/** Set up a guard to complain if we try to do certain things (like take a lock) after calling fork */
void setup_fork_guards(void);
/** Save the value of tcgetpgrp so we can restore it on exit */
void save_term_foreground_process_group(void);
void restore_term_foreground_process_group(void);
/** Return whether we are the child of a fork */
bool is_forked_child(void);
void assert_is_not_forked_child(const char *who);
#define ASSERT_IS_NOT_FORKED_CHILD_TRAMPOLINE(x) assert_is_not_forked_child(x)
#define ASSERT_IS_NOT_FORKED_CHILD() ASSERT_IS_NOT_FORKED_CHILD_TRAMPOLINE(__FUNCTION__)
extern "C" {
__attribute__((noinline)) void debug_thread_error(void);
}
#endif

2175
complete.c

File diff suppressed because it is too large Load Diff

2034
complete.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -12,10 +12,11 @@
*/
#define FISH_COMPLETE_H
#include <wchar.h>
#include "util.h"
#include "common.h"
/**
Use all completions
*/
@@ -66,46 +67,60 @@
*/
#define PROG_COMPLETE_SEP L'\t'
/**
Do not insert space afterwards if this is the only completion. (The
default is to try insert a space)
*/
#define COMPLETE_NO_SPACE 1
enum {
/**
Do not insert space afterwards if this is the only completion. (The
default is to try insert a space)
*/
COMPLETE_NO_SPACE = 1 << 0,
/**
This compeltion is case insensitive.
/**
This compeltion is case insensitive.
Warning: The contents of the completion_t structure is actually
different if this flag is set! Specifically, the completion string
contains the _entire_ completion token, not only the current
*/
#define COMPLETE_NO_CASE 2
Warning: The contents of the completion_t structure is actually
different if this flag is set! Specifically, the completion string
contains the _entire_ completion token, not only the current
*/
COMPLETE_NO_CASE = 1 << 1,
/**
This compeltion is the whole argument, not just the remainder. This
flag must never be set on completions returned from the complete()
function. It is strictly for internal use in the completion code.
*/
#define COMPLETE_WHOLE_ARGUMENT 4
/**
This compeltion is the whole argument, not just the remainder. This
flag must never be set on completions returned from the complete()
function. It is strictly for internal use in the completion code.
*/
COMPLETE_WHOLE_ARGUMENT = 1 << 2,
/**
This completion may or may not want a space at the end - guess by
checking the last character of the completion.
*/
#define COMPLETE_AUTO_SPACE 8
/**
This completion may or may not want a space at the end - guess by
checking the last character of the completion.
*/
COMPLETE_AUTO_SPACE = 1 << 3,
typedef struct
/**
This completion should be inserted as-is, without escaping.
*/
COMPLETE_DONT_ESCAPE = 1 << 4
};
typedef int complete_flags_t;
class completion_t
{
private:
/* No public default constructor */
completion_t();
public:
/**
The completion string
*/
const wchar_t *completion;
wcstring completion;
/**
The description for this completion
*/
const wchar_t *description;
wcstring description;
/**
Flags determining the completion behaviour.
@@ -118,10 +133,30 @@ typedef struct
is case insensitive.
*/
int flags;
bool is_case_insensitive() const { return !! (flags & COMPLETE_NO_CASE); }
/* Construction. Note: defining these so that they are not inlined reduces the executable size. */
completion_t(const wcstring &comp, const wcstring &desc = L"", int flags_val = 0);
completion_t(const completion_t &);
completion_t &operator=(const completion_t &);
/* The following are needed for sorting and uniquing completions */
bool operator < (const completion_t& rhs) const;
bool operator == (const completion_t& rhs) const;
bool operator != (const completion_t& rhs) const;
};
}
completion_t;
enum complete_type_t {
COMPLETE_DEFAULT,
COMPLETE_AUTOSUGGEST
};
/** Given a list of completions, returns a list of their completion fields */
wcstring_list_t completions_to_wcstring_list( const std::vector<completion_t> &completions );
/** Sorts a list of completions */
void sort_completions( std::vector<completion_t> &completions);
/**
@@ -163,68 +198,59 @@ typedef struct
\param comp A space separated list of completions which may contain subshells.
\param desc A description of the completion.
\param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used.
\param flags A set of completion flags
*/
void complete_add( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
const wchar_t *long_opt,
int long_mode,
int result_mode,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc,
int flags );
bool cmd_is_path,
wchar_t short_opt,
const wchar_t *long_opt,
int long_mode,
int result_mode,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc,
int flags );
/**
Sets whether the completion list for this command is complete. If
true, any options not matching one of the provided options will be
flagged as an error by syntax highlighting.
*/
void complete_set_authoritative( const wchar_t *cmd,
int cmd_type,
int authoritative );
void complete_set_authoritative( const wchar_t *cmd, bool cmd_type, bool authoritative );
/**
Remove a previously defined completion
*/
void complete_remove( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
const wchar_t *long_opt );
bool cmd_is_path,
wchar_t short_opt,
const wchar_t *long_opt );
/** Find all completions of the command cmd, insert them into out. If to_load is not NULL, append all commands that we would autoload, but did not (presumably because this is not the main thread) */
void complete( const wcstring &cmd, std::vector<completion_t> &comp, complete_type_t type, wcstring_list_t *to_load = NULL );
/**
Find all completions of the command cmd, insert them into out. The
caller must free the variables returned in out. The results are
returned in the array_list_t 'out', in the format of wide character
strings, with each element consisting of a suggested completion and
a description of what kind of object this completion represents,
separated by a separator of type COMPLETE_SEP.
Print a list of all current completions into the string.
Values returned by this function should be freed by the caller.
\param out The string to write completions to
*/
void complete( const wchar_t *cmd, array_list_t *out );
/**
Print a list of all current completions into the string_buffer_t.
\param out The string_buffer_t to write completions to
*/
void complete_print( string_buffer_t *out );
void complete_print( wcstring &out );
/**
Tests if the specified option is defined for the specified command
*/
int complete_is_valid_option( const wchar_t *str,
const wchar_t *opt,
array_list_t *errors );
int complete_is_valid_option( const wcstring &str,
const wcstring &opt,
wcstring_list_t *inErrorsOrNull,
bool allow_autoload );
/**
Tests if the specified argument is valid for the specified option
and command
*/
int complete_is_valid_argument( const wchar_t *str,
const wchar_t *opt,
const wchar_t *arg );
bool complete_is_valid_argument( const wcstring &str,
const wcstring &opt,
const wcstring &arg );
/**
@@ -236,20 +262,18 @@ int complete_is_valid_argument( const wchar_t *str,
\param cmd the command for which to load command-specific completions
\param reload should the commands completions be reloaded, even if they where previously loaded. (This is set to true on actual completions, so that changed completion are updated in running shells)
*/
void complete_load( const wchar_t *cmd, int reload );
void complete_load( const wcstring &cmd, bool reload );
/**
Create a new completion entry
\param context The halloc context to use for allocating new memory
\pram comp The completion string
\param completions The array of completions to append to
\param comp The completion string
\param desc The description of the completion
\param flags completion flags
*/
void completion_allocate( array_list_t *context,
const wchar_t *comp,
const wchar_t *desc,
int flags );
void append_completion(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc = L"", int flags = 0);
#endif

View File

@@ -9,29 +9,37 @@
# configure the build process.
#
AC_INIT(fish,1.23.0,fish-users@lists.sf.net)
AC_INIT(fish,2.0.0,fish-users@lists.sf.net)
#
# preserve configure arguments for xsel
#
conf_arg=$@
#
# List of output variables produced by this configure script
#
AC_SUBST( docdir )
AC_SUBST( HAVE_GETTEXT )
AC_SUBST( LDFLAGS_FISH )
AC_SUBST( LIBS_FISH )
AC_SUBST( LIBS_FISH_INDENT )
AC_SUBST( LIBS_FISH_PAGER )
AC_SUBST( LIBS_FISHD )
AC_SUBST( LIBS_MIMEDB )
AC_SUBST( LIBS_SET_COLOR )
AC_SUBST( localedir )
AC_SUBST( optbindirs )
AC_SUBST( prefix )
AC_SUBST( SEQ_FALLBACK )
AC_SUBST( XSEL )
AC_SUBST( XSEL_MAN )
AC_SUBST( XSEL_MAN_PATH )
AC_SUBST(docdir)
AC_SUBST(HAVE_GETTEXT)
AC_SUBST(LDFLAGS_FISH)
AC_SUBST(LIBS_FISH)
AC_SUBST(LIBS_FISH_INDENT)
AC_SUBST(LIBS_FISH_PAGER)
AC_SUBST(LIBS_FISHD)
AC_SUBST(LIBS_MIMEDB)
AC_SUBST(LIBS_SET_COLOR)
AC_SUBST(localedir)
AC_SUBST(optbindirs)
AC_SUBST(prefix)
AC_SUBST(SEQ_FALLBACK)
AC_SUBST(XSEL)
AC_SUBST(XSEL_MAN)
AC_SUBST(XSEL_BIN)
AC_SUBST(XSEL_MAN_PATH)
#
# If needed, run autoconf to regenerate the configure file
@@ -54,7 +62,7 @@ if test configure -ot configure.ac; then
fi
exit 1
else
AC_MSG_ERROR(
AC_MSG_ERROR(
[cannot find the autoconf program in your path.
This program needs to be run whenever the configure.ac file is modified.
Please install it and try again.]
@@ -79,7 +87,7 @@ if test ! -f ./config.h.in -o config.h.in -ot configure.ac; then
AC_MSG_NOTICE([running autoheader])
autoheader || exit 1
else
AC_MSG_ERROR(
AC_MSG_ERROR(
[cannot find the autoheader program in your path.
This program needs to be run whenever the configure.ac file is modified.
Please install it and try again.]
@@ -98,13 +106,14 @@ fi
# This mostly helps OS X users, since fink usually installs out of
# tree and doesn't update CFLAGS.
#
# It also helps FreeBSD which puts libiconv in /usr/local/lib
for i in /usr/pkg /sw /opt /opt/local; do
for i in /usr/pkg /sw /opt /opt/local /usr/local; do
AC_MSG_CHECKING([for $i/include include directory])
if test -d $i/include; then
AC_MSG_RESULT(yes)
CPPFLAGS="$CPPFLAGS -I$i/include/"
CXXFLAGS="$CXXFLAGS -I$i/include/"
CFLAGS="$CFLAGS -I$i/include/"
else
AC_MSG_RESULT(no)
@@ -113,7 +122,7 @@ for i in /usr/pkg /sw /opt /opt/local; do
AC_MSG_CHECKING([for $i/lib library directory])
if test -d $i/lib; then
AC_MSG_RESULT(yes)
LDFLAGS="$LDFLAGS -L$i/lib/ -R$i/lib/"
LDFLAGS="$LDFLAGS -L$i/lib/ -Wl,-rpath,$i/lib/"
else
AC_MSG_RESULT(no)
fi
@@ -130,7 +139,7 @@ done
#
# Tell autoconf to create config.h header
# Tell autoconf to create config.h header
#
AC_CONFIG_HEADERS(config.h)
@@ -144,8 +153,8 @@ AH_BOTTOM([#if __GNUC__ >= 3
#define __warn_unused __attribute__ ((warn_unused_result))
#define __sentinel __attribute__ ((sentinel))
#else
#define __warn_unused
#define __sentinel
#define __warn_unused
#define __sentinel
#endif])
@@ -153,10 +162,7 @@ AH_BOTTOM([#if __GNUC__ >= 3
# Set up various programs needed for install
#
# Here we look for c99 before cc as Sun Studio compiler supports c99
# through the c99 binary.
AC_PROG_CC([gcc c99 cc])
AC_PROG_CXX([g++ c++])
AC_PROG_CPP
AC_PROG_INSTALL
@@ -195,20 +201,22 @@ fi
# Optionally drop xsel command
#
AC_ARG_WITH(
xsel,
AC_ARG_WITH(
xsel,
AC_HELP_STRING(
[--without-xsel],
[do not build the xsel program needed for X clipboard integration]
[do not build the xsel program needed for X clipboard integration.
If build xsel, it will be configured with the same options as fish.]
),
[xsel=$withval],
[xsel=with_xsel]
[xsel=with_xsel]
)
if [[ "$xsel" = "with_xsel" ]]; then
XSEL=xsel-0.9.6/xsel
XSEL=xsel-1.2.0
XSEL_BIN=$XSEL/xsel
XSEL_MAN=xsel.1x
XSEL_MAN_PATH=xsel-0.9.6/xsel.1x
XSEL_MAN_PATH=$XSEL/xsel.1x
fi
@@ -226,60 +234,18 @@ AC_ARG_WITH(
[local_gettext=yes]
)
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_DEFINE([USE_GETTEXT],[1],[Perform string translations with gettext])
fi
#
# Test if the compiler accepts the -std=c99 flag. If so, using it
# increases the odds of correct compilation, since we want to use the
# *wprintf functions, which where defined in C99.
#
# NOTE: Never versions of autoconf has AC_CHECK_PROG_CC_C99
#
if test "$CC" != "c99"; then
XCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -std=c99"
XCPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -std=c99"
AC_MSG_CHECKING(if -std=c99 works)
AC_CACHE_VAL(
local_cv_has__std_c99,
[
AC_TRY_RUN(
[
#include <stdlib.h>
#include <stdio.h>
int main()
{
return 0;
}
],
local_cv_has__std_c99=yes,
local_cv_has__std_c99=no,
)
]
)
AC_MSG_RESULT($local_cv_has__std_c99)
case x$local_cv_has__std_c99 in
xno)
CFLAGS="$XCFLAGS"
CPPFLAGS="$XCPPFLAGS" ;;
esac
fi
#
# Try to enable large file support. This will make sure that on systems
# where off_t can be either 32 or 64 bit, the latter size is used. On
# other systems, this should do nothing. (Hopefully)
#
CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64"
CXXFLAGS="$CXXFLAGS -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64"
#
# If we are using gcc, set some flags that increase the odds of the
@@ -298,14 +264,15 @@ if test "$GCC" = yes; then
# bug has been verified to not exist on Linux using GCC 3.3.3.
#
CFLAGS="$CFLAGS -fno-optimize-sibling-calls"
CXXFLAGS="$CXXFLAGS -fno-optimize-sibling-calls"
#
# -Wall is there to keep me on my toes
#
CFLAGS="$CFLAGS -Wall"
# Some day...
CXXFLAGS="$CXXFLAGS -Wall"
#
# This is needed in order to get the really cool backtraces
@@ -338,9 +305,9 @@ AC_RUN_IFELSE(
return STATUS;
]
)
],
[glibc=yes],
[glibc=no]
],
[glibc=yes],
[glibc=no]
)
if test "$glibc" = yes; then
@@ -383,7 +350,7 @@ fi
AC_MSG_CHECKING([if we are under Solaris])
case $target_os in
solaris*)
solaris*)
AC_DEFINE( __EXTENSIONS__, 1, [Macro to enable additional prototypes under Solaris])
AC_MSG_RESULT(yes)
;;
@@ -397,7 +364,7 @@ AC_MSG_CHECKING([if we are using non varargs tparm.])
AC_COMPILE_IFELSE(
[
AC_LANG_PROGRAM(
[
[
#include <curses.h>
#include <term.h>
],
@@ -406,8 +373,8 @@ AC_COMPILE_IFELSE(
]
)
],
[tparm_solaris_kludge=no],
[tparm_solaris_kludge=yes]
[tparm_solaris_kludge=no],
[tparm_solaris_kludge=yes]
)
if test "x$tparm_solaris_kludge" = "xyes"; then
AC_MSG_RESULT(yes)
@@ -427,7 +394,7 @@ fi
AC_MSG_CHECKING([if we are under BSD])
case $target_os in
*bsd*)
*bsd*)
AC_DEFINE( __BSD_VISIBLE, 1, [Macro to enable additional prototypes under BSD])
AC_DEFINE( _NETBSD_SOURCE, 1, [Macro to enable additional prototypes under BSD])
AC_MSG_RESULT(yes)
@@ -486,7 +453,7 @@ AC_CHECK_FILES([/proc/self/stat])
#
AC_DEFINE(
[HAVE_TRANSLATE_H],
[HAVE_TRANSLATE_H],
[1],
[Define to 1 if the wgettext function should be used for translating strings.]
)
@@ -504,68 +471,74 @@ LIBS_COMMON=$LIBS
LIBS=""
AC_SEARCH_LIBS( connect, socket, , [AC_MSG_ERROR([Cannot find the socket library, needed to build this package.] )] )
AC_SEARCH_LIBS( nanosleep, rt, , [AC_MSG_ERROR([Cannot find the rt library, needed to build this package.] )] )
AC_SEARCH_LIBS( pthread_create, pthread, , [AC_MSG_ERROR([Cannot find the pthread library, needed to build this package.] )] )
AC_SEARCH_LIBS( setupterm, [ncurses curses], , [AC_MSG_ERROR([Could not find a curses implementation, needed to build fish])] )
AC_SEARCH_LIBS( [nan], [m], [AC_DEFINE( [HAVE_NAN], [1], [Define to 1 if you have the nan function])] )
LIBS_SHARED=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fish.
# Check for libraries needed by fish.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
# Check for libiconv_open if we can't find iconv_open. Silly OS X does
# weird macro magic for the sole purpose of amusing me.
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_SEARCH_LIBS( libiconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )] )
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
LIBS_FISH=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fish_indent.
# Check for libraries needed by fish_indent.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
LIBS_FISH_INDENT=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fish_pager.
# Check for libraries needed by fish_pager.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_SEARCH_LIBS( libiconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )] )
LIBS_FISH_PAGER=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fishd.
# Check for libraries needed by fishd.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_SEARCH_LIBS( libiconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )] )
LIBS_FISHD=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by mimedb.
# Check for libraries needed by mimedb.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
LIBS_MIMEDB=$LIBS
@@ -573,12 +546,12 @@ LIBS=$LIBS_COMMON
#
# Check for libraries needed by set_color
# Check for libraries needed by set_color
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
LIBS_SET_COLOR=$LIBS
@@ -588,14 +561,14 @@ LIBS=$LIBS_COMMON
# Check presense of various header files
#
AC_CHECK_HEADERS([getopt.h termio.h sys/resource.h term.h ncurses/term.h ncurses.h curses.h stropts.h siginfo.h sys/select.h sys/ioctl.h sys/termios.h libintl.h execinfo.h])
AC_CHECK_HEADERS([getopt.h termio.h sys/resource.h term.h ncurses/term.h ncurses.h curses.h stropts.h siginfo.h sys/select.h sys/ioctl.h sys/termios.h libintl.h execinfo.h spawn.h])
AC_CHECK_HEADER(
[regex.h],
[
AC_DEFINE(
[HAVE_REGEX_H],
[1],
[HAVE_REGEX_H],
[1],
[Define to 1 if you have the <regex.h> header file.]
)
],
@@ -632,7 +605,7 @@ AC_CHECK_HEADER(
# conditional definition of __EXTENSIONS__, to avoid redundant tests.
#
XCFLAGS="$CFLAGS"
XCFLAGS="$CXXFLAGS"
echo Checking how to use -D_XOPEN_SOURCE=600 and -D_POSIX_C_SOURCE=200112L...
local_found_posix_switch=no
@@ -682,20 +655,20 @@ for i in "" "-D_POSIX_C_SOURCE=200112L" "-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=2
[
/* Avert high-level optimisation, by making the program's
* return value depend on all tested identifiers. */
int ret = 0;
long ret = 0;
/* POSIX only: might be unhidden by _POSIX_C_SOURCE. */
struct sigaction sa;
sigset_t ss;
siginfo_t info;
ret += (int)(void *)&info + kill( 0, 0 ) +
ret += (long)(void *)&info + kill( 0, 0 ) +
sigaction( 0, &sa, 0 ) + sigemptyset( &ss );
/* Extended-POSIX: might be unhidden by _XOPEN_SOURCE. */
ret += killpg( 0, 0 );
/* Non-standard: might be hidden by the macros. */
{
{
struct winsize termsize;
ret += (int)(void *)&termsize;
ret += SIGWINCH + TIOCGWINSZ + SIGIO;
ret += (long)(void *)&termsize;
ret += SIGWINCH + TIOCGWINSZ + SIGIO;
}
return ret;
@@ -739,7 +712,7 @@ AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols sysconf )
# the translations should be installed.
#
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_CHECK_FUNC( gettext, HAVE_GETTEXT=1, HAVE_GETTEXT=0 )
fi
@@ -763,22 +736,22 @@ AC_RUN_IFELSE(
#include <stdlib.h>
],
[
int status;
char *res;
res = realpath( "somefile", 0 );
status = !(res != 0 || errno == ENOENT);
int status;
char *res;
res = realpath( "somefile", 0 );
status = !(res != 0 || errno == ENOENT);
exit( status );
]
)
],
[have_realpath_null=yes],
[have_realpath_null=no]
],
[have_realpath_null=yes],
[have_realpath_null=no]
)
if test "$have_realpath_null" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE_REALPATH_NULL],
[HAVE_REALPATH_NULL],
[1],
[Define to 1 if realpath accepts null for its second argument.]
)
@@ -805,15 +778,15 @@ AC_LINK_IFELSE(
#endif
],
[
struct winsize termsize = {0};
struct winsize termsize = {0};
TIOCGWINSZ;
]
)
],
],
[
AC_MSG_RESULT(yes);
AC_MSG_RESULT(yes);
AC_DEFINE([HAVE_WINSIZE], [1], [Define to 1 if the winsize struct and TIOCGWINSZ macro exist])
],
],
[
AC_MSG_RESULT(no)
]
@@ -849,7 +822,7 @@ if test "$ac_cv_func_fwprintf" = yes; then
[
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_BROKEN_FWPRINTF], [1], [Define to 1 one if the implemented fwprintf is broken])
]
]
)
fi
@@ -865,19 +838,19 @@ AC_TRY_LINK(
],
[
extern int _nl_msg_cat_cntr;
int tmp = _nl_msg_cat_cntr;
int tmp = _nl_msg_cat_cntr;
exit(tmp);
],
have__nl_msg_cat_cntr=yes,
have__nl_msg_cat_cntr=yes,
have__nl_msg_cat_cntr=no
)
if test "$have__nl_msg_cat_cntr" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE__NL_MSG_CAT_CNTR],
[HAVE__NL_MSG_CAT_CNTR],
[1],
[Define to 1 if the _nl_msg_cat_cntr symbol is exported.]
)
)
else
AC_MSG_RESULT(no)
fi
@@ -890,19 +863,19 @@ AC_TRY_LINK(
],
[
extern char **__environ;
char **tmp = __environ;
char **tmp = __environ;
exit(tmp!=0);
],
have___environ=yes,
have___environ=yes,
have___environ=no
)
if test "$have___environ" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE___ENVIRON],
[HAVE___ENVIRON],
[1],
[Define to 1 if the __environ symbol is exported.]
)
)
else
AC_MSG_RESULT(no)
fi
@@ -919,26 +892,26 @@ AC_TRY_LINK(
static struct option
long_options[] =
{
0, 0, 0, 0
0, 0, 0, 0
}
;
int opt = getopt_long( 0,
0,
0,
long_options,
0,
long_options,
0 );
],
have_working_getopt_long=yes,
have_working_getopt_long=yes,
have_working_getopt_long=no
)
if test "$have_working_getopt_long" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE_WORKING_GETOPT_LONG],
[HAVE_WORKING_GETOPT_LONG],
[1],
[Define to 1 if getopt_long exists and works.]
)
)
else
AC_MSG_RESULT(no)
fi
@@ -970,6 +943,12 @@ if test ! x$local_found_posix_switch = xyes; then
echo "Some fish features may be disabled."
fi
if [[ "$xsel" = "with_xsel" ]]; then
echo "Now configure xsel with $conf_arg"
rm -rf $XSEL
tar xf $XSEL.tar.gz
cd $XSEL && ./configure $conf_arg
fi
echo "fish is now configured."
echo "Use 'make' and 'make install' to build and install fish."

View File

@@ -12,7 +12,7 @@ shells. For other uses, it is recommended to define a <a
href='#function'>function</a>.
Alias does not keep track of which functions have been defined using
alias, nor does it allow erasing of aliases.
alias, nor does it allow erasing of aliases.
- NAME is the name of the function to define
- DEFINITION is the body of the function. The string " $argv" will be appended to the body.

View File

@@ -17,7 +17,7 @@ variable.
\subsection and-example Example
The following code runs the \c make command to build a program, if the
build succceeds, the program is installed. If either step fails,
build succeeds, the program is installed. If either step fails,
<tt>make clean</tt> is run, which removes the files created by the
build process

View File

@@ -37,7 +37,7 @@ In the following code, all output is redirected to the file out.html.
begin
echo $xml_header
echo $html_header
if test -e $file
if test -e $file
...
end
...

View File

@@ -8,9 +8,15 @@
The <tt>bind</tt> builtin causes fish to add a key binding from the specified sequence.
SEQUENCE is the character sequence to bind to. Usually, one would use
fish escape sequences to express them. For example, Alt-w can be
written as <tt>\\ew</tt>, and Control-x can be written as
<tt>\\cx</tt>.
fish escape sequences to express them. For example, because pressing
the Alt key and another character sends that character prefixed with
an escape character, Alt-based key bindings can be written using the
\c \\e escape. For example, Alt-w can be written as
<tt>\\ew</tt>. Control character can be written in much the same way
using the \c \\c escape, for example Control-x can be written as
<tt>\\cx</tt>. Note that Alt-based key bindings are case sensitive and
Control base key bindings are not. This is not a design choice in
fish, it is simply how terminals work.
If SEQUENCE is the empty string, i.e. an empty set of quotes, this is
interpreted as the default keybinding. It will be used whenever no
@@ -39,6 +45,9 @@ bind to the function name. This way it becomes significantly easier to
test the function while editing, and the result is usually more
readable as well.
If you want to autoload bindings each time you start shell, you should
define them inside fish_user_key_bindings function.
- <tt>-a</tt> or <tt>--all</tt> If --key-names is specified, show all key names, not only the ones that actually are defined for the current terminal. If erase mode is specified, this switch will cause all current bindings to be erased.
- <tt>-e</tt> or <tt>--erase</tt> Erase mode. All non-switch arguments are interpreted as character sequences and any commands associated with those sequences are erased.
- <tt>-h</tt> or <tt>--help</tt> Display help and exit

View File

@@ -19,7 +19,7 @@ regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the
syntax may look a bit like C switch statements, it behaves more like
the case statementes of traditional shells.
the case statements of traditional shells.
Also note that command substitutions in a case statement will be
evaluated even if it's body is not taken. This may seem

View File

@@ -13,9 +13,9 @@
The following switches change what the commandline builtin does
- \c -C or \c --cursor set or get the current cursor position, not
- \c -C or \c --cursor set or get the current cursor position, not
the contents of the buffer. If no argument is given, the current
cursor position is printed, otherwise the argument is interpreted
cursor position is printed, otherwise the argument is interpreted
as the new cursor position.
- \c -f or \c --function inject readline functions into the
reader. This option can not be combined with any other option. It
@@ -44,7 +44,7 @@ or updated
- \c -t or \c --current-token select the current token.
The following switch changes the way \c commandline prints the current
commandline buffer
commandline buffer
- \c -c or \c --cut-at-cursor only print selection up until the
current cursor position

View File

@@ -1,5 +1,5 @@
/** \page commands Commands, functions and builtins bundled with fish
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
@command_list@

View File

@@ -6,7 +6,7 @@
\subsection complete-description Description
For an introduction to how to specify completions, see the section <a
href='index.html#completions-own'>Writing your own completions</a> of
href='index.html#completion-own'>Writing your own completions</a> of
the fish manual.
- <tt>COMMAND</tt> is the name of the command for which to add a completion

View File

@@ -5,6 +5,7 @@
\subsection contains-description Description
- \c -i or \c --index print the the word index
- \c -h or \c --help display this message
Test if the set VALUES contains the string KEY. Return status is 0 if

View File

@@ -7,8 +7,8 @@ design fish. The fish design has three high level goals. These are:
-# Everything that can be done in other shell languages should be
possible to do in fish, though fish may rely on external commands in
doing so.
-# Fish should be user friendly, but not at the expense of expressiveness.
doing so.
-# Fish should be user friendly, but not at the expense of expressiveness.
Most tradeoffs between power and ease of use can be avoided with careful design.
-# Whenever possible without breaking the above goals, fish should
follow the Posix syntax.
@@ -33,7 +33,7 @@ program harder to maintain and update.
Examples:
- Here documents are too similar to using echo inside of a pipeline.
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
- Having both aliases and functions is confusing, especially since both of them have limitations and problems. \c fish functions have none of the drawbacks of either syntax.
- The many Posix quoting styles are silly, especially \$''.
@@ -57,14 +57,14 @@ take the whole system down.
Examples:
- Builtin commands should only be created when it cannot be
avoided. \c echo, \c kill, \c printf and \c time are among the commands
that fish does not implement internally since they can be provided as
external commands. Several other commands that are commonly implemented
avoided. \c echo, \c kill, \c printf and \c time are among the commands
that fish does not implement internally since they can be provided as
external commands. Several other commands that are commonly implemented
as builtins and can not be implemented as external commands,
including \c type, \c vared, \c pushd and \c popd are implemented as shellscript
functions in fish.
- Mathematical calculations, regex matching, generating lists of numbers
and many other funtions can easily be done in external programs. They
and many other funtions can easily be done in external programs. They
should not be supported internally by the shell.
The law of minimalism does not imply that a large feature set is
@@ -122,8 +122,8 @@ Examples:
- There should only be one type of input to the shell, lists of commands. Loops, conditionals and variable assignments are all performed through regular commands.
- The differences between builtin commands, shellscript functions and builtin commands should be made as small as possible. Builtins and shellscript functions should have exactly the same types of argument expansion as other commands, should be possible to use in any position in a pipeline, and should support any io redirection.
- Instead of forking when performing command substitution to provide a fake variable scope, all fish commands are performed from the same process, and fish instead supports true scoping
- All blocks end with the \c end builtin
- Instead of forking when performing command substitution to provide a fake variable scope, all fish commands are performed from the same process, and fish instead supports true scoping.
- All blocks end with the \c end builtin.
\section disc The law of discoverability
@@ -147,7 +147,7 @@ until the next time she/he uses the same program.
Examples:
- Everything should be tab-completable, and every tab completion should have a description
- Everything should be tab-completable, and every tab completion should have a description.
- Every syntax error and error in a builtin command should contain an error message describing what went wrong and a relevant help page. Whenever possible, errors should be flagged red by the syntax highlighter.
- The help manual should be easy to read, easily available from the shell, complete and contain many examples
- The language should be uniform, so that once the user understands the command/argument syntax, he will know the whole language, and be able to use tab-completion to discover new featues.

View File

@@ -3,6 +3,6 @@
\subsection dirh-synopsis Synopsis
<tt>dirh</tt>
\subsection dirh-description Description
\subsection dirh-description Description
<tt>dirh</tt> prints the current directory history. The current position in the
history is highlighted using <tt>$fish_color_history_current</tt>.

View File

@@ -3,5 +3,5 @@
\subsection dirs-synopsis Synopsis
<tt>dirs</tt>
\subsection dirs-description Description
\subsection dirs-description Description
<tt>dirs</tt> prints the current directory stack.

16
doc_src/echo.txt Normal file
View File

@@ -0,0 +1,16 @@
\section echo echo - display a line of text
\subsection echo-synopsis Synopsis
<tt>echo [STRING]</tt>
\subsection echo-description Description
Display a line of text.
- \c -n, \c Do not output a newline
- \c -s, \c Do not separate arguments with spaces
- \c -h, \c --help Display this help
\subsection echo-example Example
<tt>echo 'Hello World'</tt> Print hello world to stdout

View File

@@ -13,5 +13,5 @@ status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and
The command <tt>if test -f foo.txt; echo foo.txt exists; else; echo foo.txt does not exist; end</tt>
will print <tt>foo.txt exists</tt> if the file foo.txt
exists and is a regular file, otherwise it will print
exists and is a regular file, otherwise it will print
<tt>foo.txt does not exist</tt>.

View File

@@ -5,7 +5,7 @@
\subsection emit-description Description
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
\subsection emit-example Example

View File

@@ -7,6 +7,7 @@
- <a href='#faq-default'>How do I make fish my default shell?</a>
- <a href='#faq-titlebar'>I'm seeing weird output before each prompt when using screen. What's wrong?</a>
- <a href='#faq-greeting'>How do I change the greeting message?</a>
- <a href='#faq-history'>Why doesn't history substitution ("!$" etc.) work?</a>
<hr>
@@ -32,7 +33,7 @@ parent is ~. This issue is not possible to fix without either making
every single command into a builtin, breaking Unix semantics or
implementing kludges in every single command.
This issue can also be seen when doing IO redirection.
This issue can also be seen when doing IO redirection.
Another related issue is that many programs that operate on recursive
directory trees, like the find command, silently ignore symlinked
@@ -55,9 +56,9 @@ feature, write <code>set CDPATH .</code> on the commandline.
If fish is unable to locate a command with a given name, fish will
test if a directory of that name exists. If it does, it is implicitly
assumed that you want to change working directory. For example, the
fastest way to switch to your home directory is to simply type
<code>~</code>.
assumed that you want to change working directory. For example, the
fastest way to switch to your home directory is to simply press
<code>~</code> and enter.
<hr>
@@ -92,8 +93,8 @@ In order to change your default shell, type:
You may need to adjust the above path to e.g. /usr/bin/fish. Use the command <code>which fish</code> if you are unsure of where fish is installed.
You will need to log out and back in again for the change to take
effect.
Unfortunatly, there is no way to make the changes take effect at once,
you will need to log out and back in again.
<hr>
@@ -104,7 +105,7 @@ Quick answer:
Run the following command in fish:
<pre>
echo function fish_title;end ~/.config/fish/config.fish
echo 'function fish_title;end' &gt; ~/.config/fish/config.fish
</pre>
Problem solved!
@@ -136,5 +137,25 @@ the greeting use:
set fish_greeting
</pre>
<hr>
\section faq-history Why doesn't history substitution ("!$" etc.) work?
Because history substitution is an awkward interface that was invented before
interactive line editing was even possible. Fish drops it in favor of
perfecting the interactive history recall interface. Switching requires a
small change of habits: if you want to modify an old line/word, first recall
it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then
type "sudo ".
Fish history recall is very simple yet effective:
- As in any modern shell, the Up arrow recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like.
- If the line you want is far back in the history, type any part of the line and then press Up one or more times. This will constrain the recall to lines that include this text, and you will get to the line you want much faster. This replaces "!vi", "!?bar.c" and the like.
- Alt+Up recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like.
- If the argument you want is far back in history (e.g. 2 lines back - that's a lot of words!), type any part of it and then press Alt+Up. This will show only arguments containing that part and you will get what you want much faster. Try it out, this is very convenient!
- If you want to reuse several arguments from the same line ("!!:3*" and the like), consider recalling the whole line and removing what you don't need (Alt+D and Alt+Backspace are your friends).
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
*/

5
doc_src/fish_config.txt Normal file
View File

@@ -0,0 +1,5 @@
\section fish_config fish_config - Start up the web-based configuration interface
\subsection fish_config-description Description
This command starts up the web-based configuration interface, which allows you to edit your colors and view your functions, variables, and history.

View File

@@ -1,15 +1,15 @@
\section fish_indent fish_indent - indenter and prettyfier
\section fish_indent fish_indent - indenter and prettifier
\subsection fish_indent-synopsis Synopsis
<tt>fish_indent [options]</tt>
\subsection fish_indent-description Description
\c fish_indent is used to indent or otherwise prettyfy a piece of fish
\c fish_indent is used to indent or otherwise prettify a piece of fish
code. \c fish_indent reads commands from standard input and outputs
them to standard output.
\c fish_indent underatands the following options:
\c fish_indent understands the following options:
- <tt>-h</tt> or <tt>--help</tt> displays this help message and then exits
- <tt>-i</tt> or <tt>--no-indent</tt> do not indent commands

View File

@@ -1,6 +1,6 @@
\section fish_prompt fish_prompt - define the apperance of the command line promp
\section fish_prompt fish_prompt - define the apperance of the command line prompt
\subsection fish_promt-synopsis Synopsis
\subsection fish_prompt-synopsis Synopsis
<pre>function fish_prompt
...
end</pre>
@@ -11,6 +11,9 @@ By defining the \c fish_prompt function, the user can choose a custom
prompt. The \c fish_prompt function is executed when the prompt is to
be shown, and the output is used as a prompt.
Please keep in mind that the function is executed by <a
href='index.html#expand-command-substitution'>command substitution</a>, and so the exit status of commands within fish_prompt will not modify the <a href="index.html#variables-status">$status</a> seen outside of fish_prompt.
\subsection fish_prompt-example Example
A simple prompt:

View File

@@ -0,0 +1,23 @@
\section fish_right_prompt fish_right_prompt - define the apperance of the right-side command line prompt
\subsection fish_right_prompt-synopsis Synopsis
<pre>function fish_right_prompt
...
end</pre>
\subsection fish_right_prompt-description Description
\c fish_right_prompt is similar to \c fish_prompt, except that it appears on the right side of the terminal window.
Multiple lines are not supported in \c fish_right_prompt.
\subsection fish_prompt-example Example
A simple right prompt:
<pre>
function fish_right_prompt -d "Write out the right prompt"
date "+%m/%d/%y"
end
</pre>

View File

@@ -0,0 +1,6 @@
\section fish_update_completions fish_update_completions - Update man-page completions
\subsection fish_update_completions-description Description
This command parses your installed man pages and writes completion files to the fish config directory. This does not overwrite custom completions.

View File

@@ -11,7 +11,7 @@ not be executed at all.
\subsection for-example Example
The command
The command
<tt>for i in foo bar baz; echo $i; end</tt>
@@ -21,5 +21,5 @@ would output:
foo
bar
baz
</pre>
</pre>

14
doc_src/funced.txt Normal file
View File

@@ -0,0 +1,14 @@
\section funced funced - edit a function interactively
\subsection funced-synopsis Synopsis
<code>funced [OPTIONS] NAME</code>
\subsection funced-description Description
Use the funced command to edit the definition of a
function. If there is no function with the name specified, a skeleton function is inserted, if a function exist, the definition will be shown in your editor or on the command line.
By default, funced edits functions using the text editor in your $EDITOR variable, if set; otherwise it uses the built-in editor.
- <code>-e command</code> or <code>--editor command</code> Open the function body inside the text editor given by the command (for example, "vi"). The command 'fish' will use the built-in editor.
- <code>-i</code> or <code>--interactive</code> Open function body in built-in editor.

12
doc_src/funcsave.txt Normal file
View File

@@ -0,0 +1,12 @@
\section funcsave funcsave - save the definition of a function to the users autoload directory
\subsection funcsave-synopsis Synopsis
<tt>funcsave FUNCTION_NAME</tt>
\subsection funcsave-description Description
funcsave is used to save the current definition of a function to
a file which will be autoloaded by current and future fish
sessions. This can be useful if you have interactively created a new
function and wish to save it for later use.

View File

@@ -6,6 +6,7 @@
\subsection function-description Description
- <code>-d DESCRIPTION</code> or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description
- <code>-e</code> or <code>--on-event EVENT_NAME</code> tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt.
- <code>-j PID</code> or <code> --on-job-exit PID</code> tells fish to run this function when the job with group id PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.
- <code>-p PID</code> or <code> --on-process-exit PID</code> tells fish to run this function when the fish child process with process id PID exits
- <code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP)
@@ -26,6 +27,11 @@ will write <code>hello</code> whenever the user enters \c hi.
If the user enters any additional arguments after the function, they
are inserted into the environment <a href="index.html#variables-arrays">variable array</a> argv.
By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href='#emit">emit</a> builtin. Fish generates the following named events:
- \c fish_prompt, which is emitted whenever a new fish prompt is about to be displayed
- \c fish_command_not_found, which is emitted whenever a command lookup failed
\subsection function-example Example
<pre>

View File

@@ -8,6 +8,7 @@
This builtin command is used to print or erase functions.
- <code>-a</code> or <code>--all</code> list all functions, even those whose name start with an underscore.
- <code>-c OLDNAME NEWNAME</code> or <code>--copy OLDNAME NEWNAME</code> creates a new function named NEWNAME, using the definition of the OLDNAME function.
- <code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> change the description of this function
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
- <code>-h</code> or <code>--help</code> display a help message and exit
@@ -17,11 +18,14 @@ This builtin command is used to print or erase functions.
The default behavior of \c functions when called with no arguments,
is to print the names and definitions of all defined functions. If any
non-switch parameters are given, only the definition of the specified
functions are printed.
functions are printed.
Automatically loaded functions can not be removed using functions
-e. Either remove the definition file or change the
$fish_function_path variable to remove autoloaded functions.
Function copies, created with -c, will not have any event/signal/on-exit
notifications that the original may have had.
The exit status of the functions builtin is the number functions
specified in the argument list that do not exist.

36
doc_src/history.txt Normal file
View File

@@ -0,0 +1,36 @@
\section history history - Show and manipulate user's command history
\subsection history-synopsis Synopsis
<pre>
history (--save | --clear)
history (--search | --delete ) (--prefix "prefix string" | --contains "search string")
</pre>
\subsection history-description Description
history is used to list, search and delete user's command history
\subsection history-examples Example
<pre>
history --save
Save all changes in history file
history --clear
Delete all history items
history --search --contains "foo"
Searches commands containing "foo" string
history --search --prefix "foo"
Searches for commands with prefix "foo"
history --delete --contains "foo"
Interactively delete commands containing string "foo"
history --delete --prefix "foo"
Interactively delete commands with prefix "foo"
history --delete "foo"
Delete command "foo" from history
</pre>

View File

@@ -1,14 +1,14 @@
\section if if - conditionally execute a command
\subsection if-synopsis Synopsis
<tt>if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end</tt>
<tt>if CONDITION; COMMANDS_TRUE...; [else if CONDITION2; COMMANDS_TRUE2...;] [else; COMMANDS_FALSE...;] end</tt>
\subsection if-description Description
<tt>if</tt> will execute the command CONDITION. If the condition's
exit status is 0, the commands COMMANDS_TRUE will execute. If the
exit status is not 0 and <tt>else</tt> is given, COMMANDS_FALSE will
be executed.
be executed.
In order to use the exit status of multiple commands as the condition
of an if block, use <a href="#begin"><tt>begin; ...; end</tt></a> and
@@ -24,10 +24,13 @@ variable.
<pre>
if test -f foo.txt
echo foo.txt exists
else if test -f bar.txt
echo bar.txt exists
else
echo foo.txt does not exist
echo foo.txt and bar.txt do not exist
end
</pre>
will print <tt>foo.txt exists</tt> if the file foo.txt
exists and is a regular file, otherwise it will print
<tt>foo.txt does not exist</tt>.
</pre>will print <tt>foo.txt exists</tt> if the file foo.txt
exists and is a regular file, otherwise it will print
<tt>bar.txt exists</tt> if the file bar.txt exists
and is a regular file, otherwise it will print
<tt>foo.txt and bar.txt do not exist</tt>.

View File

@@ -11,7 +11,7 @@ This is the documentation for \c fish, the friendly interactive
shell. \c fish is a user friendly commandline shell intended
mostly for interactive use. A shell is a program used to execute other
programs. For the latest information on \c fish, please visit the <a
href="http://www.fishshell.org"><code>fish</code> homepage</a>.
href="http://ridiculousfish.com/shell/"><code>fish</code> homepage</a>.
\section syntax Syntax overview
@@ -59,7 +59,7 @@ Here is a list of some useful commands:
- \c mv, move (rename) files
- \c cp, copy files
- \c open, open files with the default application associated with each filetype
- \c less, list the contents of files
- \c less, list the contents of files
Commands and parameters are separated by the space character
(&nbsp;). Every command ends with either a newline (i.e. by pressing
@@ -80,7 +80,7 @@ while '-f' will turn it off.
\subsection quotes Quotes
Sometimes features such as <a href="#globbing">parameter expansion</a>
Sometimes features such as <a href="#expand">parameter expansion</a>
and <a href="#escapes">character escapes</a> get in the way. When that
happens, the user can write a parameter within quotes, either '
(single quote) or " (double quote). There is one important difference
@@ -124,7 +124,7 @@ these characters, so called escape sequences are provided. These are:
- <code>'\\*'</code>, escapes the star character
- <code>'\\?'</code>, escapes the question mark character
- <code>'\\~'</code>, escapes the tilde character
- <code>'\\%'</code>, escapes the percent character
- <code>'\\%%'</code>, escapes the percent character
- <code>'\\#'</code>, escapes the hash character
- <code>'\\('</code>, escapes the left parenthesis character
- <code>'\\)'</code>, escapes the right parenthesis character
@@ -135,11 +135,15 @@ these characters, so called escape sequences are provided. These are:
- <code>'\\\<'</code>, escapes the less than character
- <code>'\\\>'</code>, escapes the more than character
- <code>'\\^'</code>, escapes the circumflex character
- <code>'\\&'</code>, escapes the ampersand character
- <code>'\\;'</code>, escapes the semicolon character
- <code>'\\"'</code>, escapes the quote character
- <code>'\\''</code>, escapes the apostrophe character
- <code>'\\x<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes the ascii character with the specified value. For example, \\x9 is the tab character.
- <code>'\\X<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes a byte of data with the specified value. If you are using a mutibyte encoding, this can be used to enter invalid strings. Only use this if you know what you are doing.
- <code>'\\<i>ooo</i>'</code>, where <code><i>ooo</i></code> is an octal number, escapes the ascii character with the specified value. For example, \\011 is the tab character.
- <code>'\\u<i>xxxx</i>'</code>, where <code><i>xxxx</i></code> is a hexadecimal number, escapes the 16-bit unicode character with the specified value. For example, \\u9 is the tab character.
- <code>'\\U<i>xxxxxxxx</i>'</code>, where <code><i>xxxxxxxx</i></code> is a hexadecimal number, escapes the 32-bit unicode character with the specified value. For example, \\U9 is the tab character.
- <code>'\\u<i>xxxx</i>'</code>, where <code><i>xxxx</i></code> is a hexadecimal number, escapes the 16-bit Unicode character with the specified value. For example, \\u9 is the tab character.
- <code>'\\U<i>xxxxxxxx</i>'</code>, where <code><i>xxxxxxxx</i></code> is a hexadecimal number, escapes the 32-bit Unicode character with the specified value. For example, \\U9 is the tab character.
- <code>'\\c<i>x</i>'</code>, where <code><i>x</i></code> is a letter of the alphabet, escapes the control sequence generated by pressing the control key and the specified letter. For example, \\ci is the tab character
\subsection redirects IO redirection
@@ -147,7 +151,7 @@ these characters, so called escape sequences are provided. These are:
Most program use three types of input/output (IO), each represented by
a number called a file descriptor (FD). These are:
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
- Standard output, FD 1, for writing, defaults to writing to the screen.
- Standard error, FD 2, for writing errors and warnings, defaults to writing to the screen.
@@ -160,13 +164,13 @@ default through a simple mechanism called a redirection.
An example of a file redirection is <code> echo hello \>output.txt</code>,
which directs the output of the echo command to the file error.txt.
- To redirect standard input, write <code>\<SOURCE_FILE</code>
- To redirect standard output, write <code>\>DESTINATION</code>
- To redirect standard error, write <code>^DESTINATION</code>
- To redirect standard input, write <code>\<SOURCE_FILE</code>
- To redirect standard output, write <code>\>DESTINATION</code>
- To redirect standard error, write <code>^DESTINATION</code>
- To redirect standard output to a file which will be appended, write <code>\>\>DESTINATION_FILE</code>
- To redirect standard error to a file which will be appended, write <code>^^DESTINATION_FILE</code>
- To redirect standard error to a file which will be appended, write <code>^^DESTINATION_FILE</code>
<code>DESTINATION</code> can be one of the following:
<code>DESTINATION</code> can be one of the following:
- A filename. The output will be written to the specified file.
- An ampersand (\&) followed by the number of another file descriptor. The file descriptor will be a duplicate of the specified file descriptor.
@@ -182,7 +186,7 @@ Any FD can be redirected in an arbitrary way by prefixing the
redirection with the number of the FD.
- To redirect input of FD number N, write <code>N\<DESTINATION</code>
- To redirect output of FD number N, write <code>N\>DESTINATION</code>
- To redirect output of FD number N, write <code>N\>DESTINATION</code>
- To redirect output of FD number N to a file which will be appended, write <code>N\>\>DESTINATION_FILE</code>
Example: <code>echo Hello 2\>-</code> and <code>echo Hello ^-</code> are
@@ -230,7 +234,7 @@ Example:
<code>emacs \&</code>
will start the emacs text editor in the background.
will start the emacs text editor in the background.
\subsection syntax-job-control Job control
@@ -306,7 +310,7 @@ a filename consisting of the name of the function plus the suffix
The default value for \$fish_function_path is \c ~/.config/fish/functions
\c /etc/fish/functions \c /usr/share/fish/functions. The exact path
to the last two of these may be slighly different depending on what
to the last two of these may be slightly different depending on what
install path prefix was chosen at configuration time. The rationale
behind having three different directories is that the first one is for
user specific functions, the second one is for system-wide additional
@@ -323,10 +327,10 @@ function already be loaded, i.e. a circular dependency.
\subsection syntax-conditional Conditional execution of code
There are four fish builtins that let you execute commands only if a
specific criterion is met. These builtins are
<a href="commands.html#if">if</a>,
<a href="commands.html#switch">switch</a>,
<a href="commands.html#and">and</a> and
specific criterion is met. These builtins are
<a href="commands.html#if">if</a>,
<a href="commands.html#switch">switch</a>,
<a href="commands.html#and">and</a> and
<a href="commands.html#or">or</a>.
The \c switch command is used to execute one of possibly many blocks
@@ -335,7 +339,7 @@ for <a href="commands.html#switch">switch</a> for more information.
The other conditionals use the <a href='#variables-status'>exit
status</a> of a command to decide if a command or a block of commands
should be executed. See the documentation for
should be executed. See the documentation for
<a href="commands.html#if">if</a>, <a href="commands.html#and">and</a>
and <a href="commands.html#or">or</a> for more information.
@@ -392,13 +396,13 @@ These are the general purpose tab completions that \c fish provides:
of these completions are simple options like the \c -l option for \c
ls, but some are more advanced. The latter include:
- The programs 'man' and 'whatis' show all installed
- The programs 'man' and 'whatis' show all installed
manual pages as completions.
- The 'make' program uses all targets in the Makefile in
- The 'make' program uses all targets in the Makefile in
the current directory as completions.
- The 'mount' command uses all mount points specified in fstab as completions.
- The 'ssh' command uses all hosts that are stored
in the known_hosts file as completions. (see the ssh documentation for more information)
- The 'ssh' command uses all hosts that are stored
in the known_hosts file as completions. (see the ssh documentation for more information)
- The 'su' command uses all users on the system as completions.
- The \c apt-get, \c rpm and \c yum commands use all installed packages as completions.
@@ -415,7 +419,7 @@ this can be specified as <code>complete -c myprog -a 'start
stop'</code>. The argument to the \c -a switch is always a single
string. At completion time, it will be tokenized on spaces and tabs,
and variable expansion, command substitution and other forms of
parameter expansion will take place.
parameter expansion will take place.
Fish has a special syntax to support specifying switches accepted by a
command. The switches \c -s, \c -l and \c -o are used to specify a
@@ -466,11 +470,11 @@ prints a list of all user groups with the groups members as description.
<pre>__fish_complete_pids</pre>
prints a list of all procceses IDs with the command name as description.
prints a list of all processes IDs with the command name as description.
<pre>__fish_complete_suffix SUFFIX</pre>
performs file completion allowing only files ending in SUFFIX. The mimetype database is usded to find a suitable description.
performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
<pre>__fish_complete_users</pre>
@@ -494,7 +498,7 @@ prints a list of all known network interfaces.
<pre>__fish_print_packages</pre>
prints a list of all installed packages. This function currently handles
debian, rpm and gentoo packages.
Debian, rpm and Gentoo packages.
@@ -509,7 +513,7 @@ of the name of the command to complete and the suffix '.fish'.
The default value for \$fish_complete_path is ~/.config/fish/completions,
/etc/fish/completions and /usr/share/fish/completions. The exact
path to the last two of these may be slighly different depending on
path to the last two of these may be slightly different depending on
what install path prefix was chosen at configuration time. If a
suitable file is found in one of these directories, it will be
automatically loaded and the search will be stopped. The rationale
@@ -519,20 +523,20 @@ completions and the last one is for default fish completions.
If you have written new completions for a common
Unix command, please consider sharing your work by sending it to <a
href='mailto: fish-users@lists.sf.net'>the fish mailinglist</a>.
href='mailto: fish-users@lists.sf.net'>the fish mailing list</a>.
\section expand Parameter expansion (Globbing)
When an argument for a program is given on the commandline, it
undergoes the process of parameter expansion before it is sent on to
the command. Parameter expansion is a powerful set of mechamisms that
the command. Parameter expansion is a powerful set of mechanisms that
allow you to expand the parameter in various ways, including
performing wildcard matching on files, inserting the value of
environment variables into the parameter or even using the output of
another command as a parameter list.
\subsection expand-wildcard Wildcards
\subsection expand-wildcard Wildcards
If a star (*) or a question mark (?) is present in the parameter, \c
fish attempts to match the given parameter to any files in such a
@@ -577,6 +581,9 @@ A command substitution will not change the value of the <a
href='#variables-status'>status</a> variable outside of the command
substitution.
Only part of the output can be used, see <a href='#expand-index-range'>index
range expansion</a> for details.
Example:
The command <code>echo (basename image.jpg .jpg).png</code> will
@@ -609,7 +616,7 @@ href="#variables"> Environment variables</a> section.
Example:
<code> echo \$HOME</code> prints the home directory of the current
user.
user.
If you wish to combine environment variables with text, you can
encase the variables within braces to embed a variable inside running
@@ -620,9 +627,8 @@ The {$USER}san syntax might need a bit of an elaboration. Posix
shells allow you to specify a variable name using '$VARNAME' or
'${VARNAME}'. Fish supports the former, and has no support whatsoever
for the latter or anything like it. So what is '{$VARNAME}' then?
Well, '{WHATEVER}' is <a href='#brace'>brace expansion</a>, identical
to that supported by e.g. bash. 'a{b,c}d' -> 'abd acd' works
both in bash and on fish. So '{$VARNAME}' is a bracket-expansion with
Well, '{WHATEVER}' is <a href='#brace'>brace expansion</a>, e.g. 'a{b,c}d' -> 'abd acd'.
So '{$VARNAME}' is a bracket-expansion with
only a single element, i.e. it becomes expanded to '$VARNAME', which
will be variable expanded to the value of the variable 'VARNAME'. So
you might think that the brackets don't actually do anything, and that
@@ -671,6 +677,50 @@ element of the foo variable should be dereferenced and never that the fifth
element of the doubly dereferenced variable foo. The latter can
instead be expressed as $$foo[1][5].
\subsection expand-index-range Index range expansion
Both command substitution and environment variables support accessing only
specific items by providing a set of indices in square brackets. It's
often needed to access a sequence of elements. To do this, one can use
range operator '..' for this. A range 'a..b', where range limits 'a' and 'b'
are integer numbers, is expanded into a sequence of indices
'a a+1 a+2 ... b' or 'a a-1 a-2 ... b' depending on which of 'a' or 'b'
is higher. The negative range limits are calculated from the end of the array
or command substitution.
Some examples:
<pre>
# Limit the command substitution output
echo (seq 10)[2..5] # will use elements from 2 to 5
# Output is:
# 2 3 4 5
# Use overlapping ranges:
echo (seq 10)[2..5 1..3] # will take elements from 2 to 5 and then elements from 1 to 3
# Output is:
# 2 3 4 5 1 2 3
# Reverse output
echo (seq 10)[-1..1] # will use elements from the last output line to the first one in reverse direction
# Output is:
# 10 9 8 7 6 5 4 3 2 1
</pre>
The same works when setting or expanding variables:
<pre>
# Reverse path variable
set PATH $PATH[-1..1]
# or
set PATH[-1..1] $PATH
# Use only n last items of the PATH
set n -3
echo $PATH[$n..-1]
</pre>
NOTE: Currently variables are allowed inside variables index expansion, but not in indices,
used for command substitution.
\subsection expand-home Home directory expansion
The ~ (tilde) character at the beginning of a parameter, followed by a
@@ -684,12 +734,12 @@ The \% (percent) character at the beginning of a parameter followed by
a string is expanded into a process id. The following expansions are
performed:
- If the string is the entire word \c self, the shells pid is the result
- If the string is the entire word \c self, the shells pid is the result.
- Otherwise, if the string is the id of a job, the result is the process
group id of the job.
- Otherwise, if any child processes match the specified string, their
pids are the result of the expansion.
- Otherwise, if any processes owned by the user match the specified
- Otherwise, if any child processes match the specified string, their
pids are the result of the expansion.
- Otherwise, if any processes owned by the user match the specified
string, their pids are the result of the expansion.
This form of expansion is useful for commands like kill and fg, which
@@ -739,7 +789,7 @@ expansion</a>.
To set a variable value, use the <a href="commands.html#set"> \c set
command</a>.
Example:
Example:
To set the variable \c smurf_color to the value \c blue, use the command
<code>set smurf_color blue</code>.
@@ -749,7 +799,7 @@ the shell through <a href="expand-variable">variable expansion</a>.
Example:
To use the value of a the variable \c smurf, write $ (dollar symbol)
To use the value of the variable \c smurf, write $ (dollar symbol)
followed by the name of the variable, like <code>echo Smurfs are
usually $smurf_color</code>, which would print the result 'Smurfs are
usually blue'.
@@ -868,8 +918,8 @@ echo $PATH[3]
</pre>
Note that array indices start at 1 in fish, not 0, as is more common
in other languages. This is because many common unix tools like seq
are more suited to such use.
in other languages. This is because many common Unix tools like seq
are more suited to such use.
If you do not use any brackets, all the elements of the array will be
written as separate items. This means you can easily iterate over an
@@ -906,6 +956,9 @@ If you specify a negative index when expanding or assigning to an
array variable, the index will be calculated from the end of the
array. For example, the index -1 means the last index of an array.
A range of indices can be specified, see <a href='#expand-index-range'>index
range expansion</a> for details.
\subsection variables-special Special variables
The user can change the settings of \c fish by changing the values of
@@ -921,14 +974,14 @@ certain environment variables.
\c fish also sends additional information to the user through the
values of certain environment variables. The user can not change the
values of most of these variables.
values of most of these variables.
- \c _, which is the name of the currently running command.
- \c argv, which is an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
- \c history, which is an array containing the last commands that where entered.
- \c HOME, which is the users home directory. This variable can only be changed by the root user.
- \c PWD, which is the current working directory.
- \c status, which is the exit status of the last foreground job to exit.
- \c PWD, which is the current working directory.
- \c status, which is the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
- \c USER, which is the username. This variable can only be changed by the root user.
The names of these variables are mostly derived from the csh family of
@@ -967,6 +1020,8 @@ variable may also be set to a specific value:
- 126 means that while a file with the specified name was located, it was not executable
- 127 means that no function, builtin or command with the given name could be located
If a process exits through a signal, the exit status will be 128 plus the number of the signal.
\subsection variables-color Variables for changing highlighting colors
The colors used by fish for syntax highlighting can be configured by
@@ -975,7 +1030,7 @@ variables can be one of the colors accepted by the <a
href='commands.html#set_color'>set_color</a> command. The \c --bold
or \c -b switches accepted by \c set_color are also accepted.
The following variables are available to change the highligting colors
The following variables are available to change the highlighting colors
in fish:
- \c fish_color_normal, the default color
@@ -999,6 +1054,7 @@ highlighting in the completion pager:
- \c fish_pager_color_completion, the color of the completion itself
- \c fish_pager_color_description, the color of the completion description
- \c fish_pager_color_progress, the color of the progress bar at the bottom left corner
- \c fish_pager_color_secondary, the background color of the every second completion
Example:
@@ -1022,7 +1078,7 @@ variables set the specified aspect of the locale information. LANG
is a fallback value, it will be used if none of the LC_ variables are
specified.
\section builtin-overview Builtins
\section builtin-overview Builtins
Many other shells have a large library of builtin commands. Most of
these commands are also available as standalone commands, but have
@@ -1040,7 +1096,7 @@ switch of the command.
The \c fish editor features copy and paste, a searchable history and
many editor functions that can be bound to special keyboard
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
Here are some of the commands available in the editor:
- Tab completes the current token
@@ -1050,7 +1106,7 @@ Here are some of the commands available in the editor:
- Alt-left and Alt-right moves one word left or right, or moves forward/backward in the directory history if the commandline is empty
- Up and down search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the <a href='#history'>history </a>section for more information on history searching.
- Alt-up and Alt-down search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the <a href='#history'>history </a>section for more information on history searching.
- Delete and backspace removes one character forwards or backwards respecitvely
- Delete and backspace removes one character forwards or backwards respectively
- Ctrl-c deletes entire line
- Ctrl-d delete one character to the right of the cursor, unless the buffer is empty, in which case the shell will exit
- Ctrl-k move contents from the cursor to the end of line to the <a href="#killring">killring</a>
@@ -1058,12 +1114,12 @@ Here are some of the commands available in the editor:
- Ctrl-l clear and repaint screen
- Ctrl-w move previous word to the <a href="#killring">killring</a>
- Alt-d move next word to the <a href="#killring">killring</a>
- Alt-w prints a short description of the command under the cursor
- Alt-l lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
- Alt-w prints a short description of the command under the cursor
- Alt-l lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
- Alt-p adds the string '| less;' to the end of the job under the cursor. The result is that the output of the command will be paged.
You can change these key bindings using the
<a href="commands.html#bind">bind</a> builtin command.
You can change these key bindings using the
<a href="commands.html#bind">bind</a> builtin command.
- \c backward-char, moves one character to the left
@@ -1094,7 +1150,7 @@ If such a script produces output, the script needs to finish by
calling 'commandline -f repaint' in order to tell fish that a repaint
is in order.
\subsection killring Copy and paste (Kill Ring)
\subsection killring Copy and paste (Kill Ring)
\c fish uses an Emacs style kill ring for copy and paste
functionality. Use Ctrl-K to cut from the current cursor position to
@@ -1105,7 +1161,7 @@ Meta-Y to rotate to the previous kill.
If the environment variable DISPLAY is set, \c fish will try to
connect to the X-windows server specified by this variable, and use
the clipboard on the X server for copying and pasting.
the clipboard on the X server for copying and pasting.
\subsection history Searchable history
@@ -1140,7 +1196,7 @@ than a single line:
- Pressing the enter key while a block of commands is unclosed, i.e. when one or more block commands such as 'for', 'begin' or 'if' do not have a corresponding 'end' command.
- Pressing Alt-enter instead of pressing the enter key.
- By backslash escaping a newline, i.e. by inserting a backslash (\\) character pefore pressing the enter key.
- By backslash escaping a newline, i.e. by inserting a backslash (\\) character before pressing the enter key.
The fish commandline editor works exactly the same in single line mode
and in multiline mode. To move between lines use the left and right
@@ -1156,7 +1212,7 @@ graphical user interface from the terminal, and then be able to
continue using the shell. In such cases, there are several ways in
which the user can change <code>fish</code>'s behavior.
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. Gnu emacs uses ^X z to stop running.
-# By using the <a href="commands.html#fg">fg</a> and <a href="commands.html#bg">bg</a> builtin commands, the user can send any currently running job into the foreground or background.
@@ -1222,8 +1278,8 @@ fish_color_substitution, \c fish_color_redirection, \c fish_color_end,
\c fish_color_error, \c fish_color_param, \c fish_color_comment, \c
fish_color_match, \c fish_color_search_match, \c fish_color_cwd, \c
fish_pager_color_prefix, \c fish_pager_color_completion, \c
fish_pager_color_description and \c
fish_pager_color_progress. Usually, the value of these variables will
fish_pager_color_description, \c fish_pager_color_progress
and \c fish_pager_color_secondary. Usually, the value of these variables will
be one of \c black, \c red, \c green, \c brown, \c yellow, \c blue, \c
magenta, \c purple, \c cyan, \c white or \c normal, but they can be an
array containing any color options for the set_color command.
@@ -1241,11 +1297,11 @@ fish_title function is executed before and after a new command is
executed or put into the foreground and the output is used as a
titlebar message. The $_ environment variable will always contain the
name of the job to be put into the foreground (Or 'fish' if control is
returning to the shell) when the fish_prompt function is called.
returning to the shell) when the \c fish_prompt function is called.
Example:
<p>
The default \c fish title is
The default \c fish title is
</p>
<p>
<pre>
@@ -1256,6 +1312,12 @@ end
</pre>
</p>
\subsection greeting Configurable greeting
If a function named fish_greeting exists after initialization, it will
be run when entering interactive mode. Otherwise,if an environment
variable named fish_greeting exists, it will be printed.
\subsection event Event handlers
When defining a new function in fish, it is possible to make it into an
@@ -1266,6 +1328,7 @@ specific event takes place. Events that can trigger a handler currently are:
- When a process or job exits
- When the value of a variable is updated
- When the prompt is about to be shown
- When a command lookup fails
Example:
@@ -1280,9 +1343,9 @@ For more information on how to define new event handlers, see the
documentation for the <a href='commands.html#function'>function</a>
command.
\subsection debuging Debuging fish scripts
\subsection debugging Debugging fish scripts
Fish includes a built in debuger. The debuger allows you to stop
Fish includes a built in debugger. The debugger allows you to stop
execution of a script at an arbitrary point and launch a prompt. This
prompt can then be used to check or change the value of any variables
or perform any shellscript command. To resume normal execution of the
@@ -1290,15 +1353,15 @@ script, simply exit the prompt.
To start the debugger, simply call the builtin command
'breakpoint'. The default action of the TRAP signal is to call this
builtin, so a running script can be debuged by sending it the TRAP
signal. Once in the debuger, it is easy to insert new breakpoints by
builtin, so a running script can be debugged by sending it the TRAP
signal. Once in the debugger, it is easy to insert new breakpoints by
using the funced function to edit the definition of a function.
\section issues Common issues with fish
If you install fish in your home directory, fish will not work
correctly for any other user than yourself. This is because fish needs
its initalization files to function properly. To solve this
its initialization files to function properly. To solve this
problem, either copy the initialization files to each fish users home
directory, or install them in /etc.
@@ -1310,15 +1373,15 @@ making a translation. Currently, only the shell itself can be
translated, a future version of fish should also include translated
manuals.
To make a translation of fish, you will first need the sourcecode,
available from the <a href='http://www.fishshell.org'>fish
To make a translation of fish, you will first need the source code,
available from the <a href='http://ridiculousfish.com/shell/'>fish
homepage</a>. Download the latest version, and then extract it using a
command like <code>tar -zxf fish-VERSION.tar.gz</code>.
Next, cd into the newly created fish directory using <code>cd
fish-VERSION</code>.
You will now need to configure the sourcecode using the command
You will now need to configure the source code using the command
<code>./configure</code>. This step might take a while.
Before you continue, you will need to know the ISO 639 language code
@@ -1326,7 +1389,7 @@ of the language you are translating to. These codes can be found <a
href='http://www.w3.org/WAI/ER/IG/ert/iso639.htm'>here</a>. For
example, the language code for Uighur is ug.
Now you have the sourcecode and it is properly configured. Lets start
Now you have the source code and it is properly configured. Lets start
translating. To do this, first create an empty translation table for
the language you wish to translate to by writing <code>make
po/[LANGUAGE CODE].po</code> in the fish terminal. For example, if you
@@ -1346,7 +1409,7 @@ msgstr ""
</pre>
The first line is the English string to translate, the second line
should contain your translation. For example, in swedish the above
should contain your translation. For example, in Swedish the above
might become:
<pre>
@@ -1370,9 +1433,9 @@ href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>.
\subsection todo-features Missing features
- Complete vi-mode key bindings
- More completions (for example konsole, gnome-terminal,
- More completions (for example konsole, gnome-terminal,
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
compress, wine, dig, batch,
compress, wine, dig, batch,
g++, javac, java, gcj, lpr, doxygen, whois)
- Undo support
- wait shellscript
@@ -1382,7 +1445,7 @@ g++, javac, java, gcj, lpr, doxygen, whois)
\subsection todo-possible Possible features
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
installed would be awesome
- suggest a completion on unique matches by writing it out in an understated color
- Highlight beginning/end of block when moving over a block command
@@ -1395,12 +1458,11 @@ g++, javac, java, gcj, lpr, doxygen, whois)
- Selectable completions in the pager
- Per process output redirection
- Reduce the space of the pager by one line to allow the commandline to remain visible.
- down-arrow could be used to save the current command to the history. Or give the next command in-sequnce. Or both.
- Drop support for inputrc-files. Use shellscripts and the bind builtin. Also, redo the syntax for the bind builtin to something more sane.
- down-arrow could be used to save the current command to the history. Or give the next command in-sequence. Or both.
- History could reload itself when the file is updated. This would need to be done in a clever way to avoid chain reactions
- The error function should probably be moved into it's own library, and be made mere general purpose.
- The code validation functions should be moved from the parser to parse_util.
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
- The code validator should warn about unknown commands.
- Auto-newlines
- A fault injector could be written to increase robustness and testing of error recovery paths
@@ -1409,24 +1471,24 @@ g++, javac, java, gcj, lpr, doxygen, whois)
- exec_subshell should be either merged with eval or moved to parser.c
- Don't use expand_string to perform completions. wildcard_complete can be called directly, the brace expansion handling should be universal, and the process expansion can be moved to complete.c.
- Make the history search support incremental searching
- An automatic logout feature
- An automatic logout feature
- Make tab completions completely silent by default, i.e. kill stderr when running completion commands. This needs to be overridalbe for debugging purposes.
- Move history to an environment variable
\subsection bugs Known bugs and issues
- Suspending and then resuming pipelines containing a builtin or a shellscript function is broken. Ideally, the exec function in exec.c should be able to resume execution of a partially executed job.
- delete-word is broken on the commandline 'sudo update-alternatives --config x-'
- Sometimes autoheader needs to be run on a fresh tarball. Fix dates before creating tarballs.
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
- There have been stray reports of issues with strang values of the PATH variable during startup.
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
- There have been stray reports of issues with strange values of the PATH variable during startup.
- bindings in config.fish are overwritten by default key bindings.
- Adding 'bind -k ...' doesn't overwrite non-keybinding binds of the same sequence.
- History file does not remove duplicates.
- History file should apply some kind of maximum history length.
- Older versions of Doxygen has bugs in the man-page generation which cause the builtin help to render incorrectly. Version 1.2.14 is known to have this problem.
If you think you have found a bug not described here, please send a
report to <a href="mailto:fish-users@lists.sf.net">fish-users@lists.sf.net</a>.
\subsection issues Known issues
Older versions of Doxygen has bugs in the man-page generation which
cause the builtin help to render incorrectly. Version 1.2.14 is known
to have this problem.
*/

View File

@@ -1,28 +1,11 @@
/** \page license Licenses
Fish Copyright (C) 2005-2006 Axel Liljencrantz. Fish is released under
<h2>License for fish</h2>
Fish Copyright (C) 2005-2009 Axel Liljencrantz. Fish is released under
the GNU General Public License, version 2. The license agreement is
included below.
Fish contains code under the BSD license, namely versions of the
two functions strlcat and strlcpy, modified for use with wide
character strings. This code is copyrighted by Todd C. Miller. The
license agreement is included below.
The XSel command, written and copyrighted by Conrad Parker, is
distributed together with, and used by fish. It is released under the MIT
license. The license agreement is included below.
The xdgmime library, written and copyrighted by Red Hat, Inc, is used
by the mimedb command, which is a part of fish. It is released under
the LGPL. The license agreement is included below.
Fish contains code from the glibc library, namely the wcstok
function. This code is licensed under the LGPL. The license agreement
is included below.
<HR>
<H2><A NAME="SEC1" HREF="gpl.html#TOC1">GNU GENERAL PUBLIC LICENSE</A></H2>
<P>
@@ -31,7 +14,7 @@ Version 2, June 1991
</P>
<PRE>
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
@@ -464,7 +447,7 @@ PERFORMANCE OF THIS SOFTWARE.
<h2>License for XSel</h2>
The XSel command, written and copyrighted by Conrad Parker, is
distributed together with \c fish.
distributed together with \c fish.
It is Copyright (C) 2001 Conrad Parker <conrad@vergenet.net>
@@ -480,6 +463,18 @@ without express or implied warranty.
<HR>
<h2>License for xdgmime and glibc</h2>
The xdgmime library, written and copyrighted by Red Hat, Inc, is used
by the mimedb command, which is a part of fish. It is released under
the LGPL, version 2 or later, or under the Academic Free License,
version 2. Version 2 of the LGPL license agreement is included below.
Fish contains code from the glibc library, namely the wcstok
function. This code is licensed under the LGPL, version 2 or
later. Version 2 of the LPGL license agreement is included below.
<H2><A NAME="SEC1" HREF="#TOC1">GNU LESSER GENERAL PUBLIC LICENSE</A></H2>
<P>
@@ -807,7 +802,7 @@ of these things:
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
<LI><STRONG>b)</STRONG> Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,

View File

@@ -9,7 +9,7 @@
math is used to perform mathematical calculations. It is only a very
thin wrapper for the bc program, that makes it possible to specify an
expression from the command line without using non-standard extensions
or a pipeline. Simply use a command like <code>math 1+1</code>.
or a pipeline. Simply use a command like <code>math 1+1</code>.
For a description of the syntax supported by math, see the manual for
the bc program. Keep in mind that parameter expansion takes place on

View File

@@ -5,7 +5,7 @@
\subsection mimedb-description Description
- \c FILES is a list of files to analyse
- \c FILES is a list of files to analyse
- \c -t, \c --input-file-data the specified files type should be determined both by their filename and by their contents (Default)
- \c -f, \c --input-filename the specified files type should be determined by their filename
- \c -i, \c --input-mime the arguments are not files but mimetypes

View File

@@ -5,7 +5,7 @@
\subsection not-description Description
The \c not builtin is used to negate the exit status of another command.
The \c not builtin is used to negate the exit status of another command.
\subsection not-example Example

View File

@@ -1,12 +1,12 @@
\section open open - open file in it's default application
\section open open - open file in its default application
\subsection open-synopsis Synopsis
<tt>open FILES...</tt>
\subsection open-description Description
The \c open command is used to open a file in it's default application. \c open is implemented using the <a href="commands.html#mimedb">mimedb</a> command.
The \c open command is used to open a file in its default application. \c open is implemented using the \c xdg-open command if it exists, or else the <a href="commands.html#mimedb">mimedb</a> command.
\subsection open-example Example
<tt>open *.txt</tt> opens all the text files in the current directory using your systems default text editor.
<tt>open *.txt</tt> opens all the text files in the current directory using your system's default text editor.

View File

@@ -17,7 +17,7 @@ variable.
\subsection or-example Example
The following code runs the \c make command to build a program, if the
build succceeds, the program is installed. If either step fails,
build succeeds, the program is installed. If either step fails,
<tt>make clean</tt> is run, which removes the files created by the
build process

View File

@@ -3,6 +3,6 @@
\subsection popd-synopsis Synopsis
<tt>popd</tt>
\subsection popd-description Description
<tt>popd</tt> removes the top directory from the directory stack and
\subsection popd-description Description
<tt>popd</tt> removes the top directory from the directory stack and
cd's to the new top directory.

View File

@@ -3,7 +3,7 @@
\subsection prevd-synopsis Synopsis
<tt>prevd [-l | --list] [pos]</tt>
\subsection prevd-description Description
\subsection prevd-description Description
<tt>prevd</tt> moves backwards <tt>pos</tt> positions in the history
of visited directories; if the beginning of the history has been hit,

View File

@@ -3,7 +3,7 @@
\subsection pushd-synopsis Synopsis
<tt>pushd [DIRECTORY]</tt>
\subsection pushd-description Description
\subsection pushd-description Description
The <tt>pushd</tt> function adds DIRECTORY to the top of the directory stack
and makes it the current directory. Use <tt>popd</tt> to pop it off and and
return to the original directory.

8
doc_src/pwd.txt Normal file
View File

@@ -0,0 +1,8 @@
\section pwd pwd - returns the current directory
\subsection pwd-synopsis Synopsis
<tt>pwd</tt>
\subsection pwd-description Description
Returns the current directory. Note that fish always resolves symbolic links in the current directory path.

View File

@@ -21,4 +21,4 @@ for i in (seq (random) -1 1)
echo $i
sleep
end
</pre>
</pre>

View File

@@ -6,12 +6,12 @@
\subsection read-description Description
The <tt>read</tt> builtin causes fish to read one line from standard
input and store the result in one or more environment variables.
input and store the result in one or more environment variables.
- <tt>-c CMD</tt> or <tt>--command=CMD</tt> specifies that the initial string in the interactive mode command buffer should be CMD.
- <tt>-e</tt> or <tt>--export</tt> specifies that the variables will be exported to subshells.
- <tt>-g</tt> or <tt>--global</tt> specifies that the variables will be made global.
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
- <tt>-l</tt> or <tt>--local</tt> specifies that the variables will be made local.
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
- <tt>-p PROMPT_CMD</tt> or <tt>--prompt=PROMPT_CMD</tt> specifies that the output of the shell command PROMPT_CMD should be used as the prompt for the interactive mode prompt. The default prompt command is <tt>set_color green; echo read; set_color normal; echo "> "</tt>.
- <code>-s</code> or <code>--shell</code> Use syntax highlighting, tab completions and command termination suitable for entering shellscript code
- <code>-u</code> or <code>--unexport</code> causes the specified environment not to be exported to child processes

View File

@@ -3,7 +3,7 @@
\subsection return-synopsis Synopsis
<tt>function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end</tt>
\subsection return-description Description
\subsection return-description Description
The \c return builtin is used to halt a currently running function. It
is usually added inside of a conditional block such as an <a

View File

@@ -1,12 +0,0 @@
\section save_function save_function - save the definition of a function to the users autoload directory
\subsection save_function-synopsis Synopsis
<tt>save_function FUNCTION_NAME</tt>
\subsection save_function-description Description
save_function is used to save the current definition of a function to
a file which will be autoloaded by current and future fish
sessions. This can be useful if you have interactively created a new
function and wish to save it for later use.

View File

@@ -7,7 +7,11 @@
Change the foreground and/or background color of the terminal.
COLOR is one of black, red, green, brown, yellow, blue, magenta,
purple, cyan, white and normal.
purple, cyan, white and normal.
If your terminal supports term256 (modern xterms and OS X Lion),
you can specify an RGB value with three or six hex digits, such
as A0FF33 or f2f. fish will choose the closest supported color.
- \c -b, \c --background Set the background color
- \c -c, \c --print-colors Prints a list of all valid color names
@@ -28,3 +32,9 @@ result in a white font color.
Not all terminal emulators support all these features. This is not a
bug in set_color but a missing feature in the terminal emulator.
set_color uses the terminfo database to look up how to change terminal
colors on whatever terminal is in use. Some systems have old and
incomplete terminfo databases, and may lack color information for
terminals that support it. Download and install the latest version of
ncurses and recompile fish against it in order to fix this issue.

View File

@@ -3,7 +3,7 @@
\subsection source-synopsis Synopsis
<tt>. FILENAME [ARGUMENTS...]</tt>
\subsection source-description Description
\subsection source-description Description
Evaluates the commands of the specified file in the current
shell. This is different from starting a new process to perform the
@@ -22,7 +22,7 @@ execute. If something goes wrong while opening or reading the file,
\subsection source-example Example
<tt>. ~/.fish</tt>
<tt>. ~/.config/fish/config.fish</tt>
causes fish to reread its initialization file.

View File

@@ -14,5 +14,5 @@
- <tt>-f</tt> or <tt>--current-filename</tt> prints the filename of the currently running script
- <tt>-n</tt> or <tt>--current-line-number</tt> prints the line number of the currently running script
- <tt>-j CONTROLTYPE</tt> or <tt>--job-control=CONTROLTYPE</tt> set the job control type. Can be one of: none, full, interactive
- <tt>-t</tt> or <tt>--print-stack-trace</tt>
- <tt>-t</tt> or <tt>--print-stack-trace</tt> prints a stack trace of all function calls on the call stack
- <tt>-h</tt> or <tt>--help</tt> display a help message and exit

43
doc_src/test.txt Normal file
View File

@@ -0,0 +1,43 @@
\section test test - perform tests on files and text
\subsection test-synopsis Synopsis
<tt>test [EXPRESSION]</tt>
\subsection test-description Description
Tests the expression given and returns true or false.
- \c -h, \c Display this help
- \c -G, \c File owned by effective group ID
- \c -L, \c File is syslink
- \c -O, \c File owned by effective user ID
- \c -S, \c File is socket
- \c -a, \c Logical and
- \c -b, \c File is block device
- \c -c, \c File is character device
- \c -d, \c File is a directory
- \c -e, \c File exists
- \c -f, \c File is regular
- \c -f, \c File is set-group-ID
- \c -k, \c File has sticky bit set
- \c -n, \c String length is non-zero
- \c -o, \c Logical or
- \c -p, \c File is named pipe
- \c -r, \c File is readable
- \c -s, \c File size is non-zero
- \c -t, \c FD is terminal
- \c -u, \c File set-user-ID bit is set
- \c -w, \c File is writable
- \c -x, \c File is executable
- \c -z, \c String length is zero
\subsection test-example Example
<pre>
if test -d "/"
echo "Fish is cool"
end
</pre>
Because "/" is a directory the expression will evaluate
to true, and "Fish is cool" will be echoed

View File

@@ -27,7 +27,7 @@ Note that not all these limits are available in all operating systems.
The value of limit can be a number in the unit specified for
the resource or one of the special values hard, soft, or unlimited,
which stand for the current hard limit, the current soft limit, and no
limit, respectively.
limit, respectively.
If limit is given, it is the new value of the specified resource. If
no option is given, then -f is assumed. Values are in kilobytes,
@@ -56,7 +56,7 @@ The fish implementation of ulimit should behave identically to the
implementation in bash, except for these differences:
- Fish ulimit supports GNU-style long options for all switches
- Fish ulimit does not support the -p option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe sixe is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
- Fish ulimit does not support the -p option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
- Fish ulimit does not support getting or setting multiple limits in one command, except reporting all values using the -a switch
\subsection ulimit-example Example

View File

@@ -1,4 +1,4 @@
\section vared vared - interactively edit the value of an environment variable
\section vared vared - interactively edit the value of an environment variable
\subsection vared-synopsis Synopsis
<tt>vared VARIABLE_NAME</tt>
@@ -7,7 +7,7 @@
vared is used to interactively edit the value of an environment
variable. Array variables as a whole can not be edited using vared,
but individual array elements can.
but individual array elements can.
\subsection vared-example Example

1554
env.c

File diff suppressed because it is too large Load Diff

1594
env.cpp Normal file

File diff suppressed because it is too large Load Diff

96
env.h
View File

@@ -6,8 +6,10 @@
#define FISH_ENV_H
#include <wchar.h>
#include <map>
#include "util.h"
#include "common.h"
/**
Flag for local (to the current block) variable
@@ -50,11 +52,20 @@ enum{
}
;
/* A struct of configuration directories, determined in main() that fish will optionally pass to env_init.
*/
struct config_paths_t
{
wcstring data; // e.g. /usr/local/share
wcstring sysconf; // e.g. /usr/local/etc
wcstring doc; // e.g. /usr/local/share/doc/fish
wcstring bin; // e.g. /usr/local/bin
};
/**
Initialize environment variable data
*/
void env_init();
void env_init(const struct config_paths_t *paths = NULL);
/**
Destroy environment variable data
@@ -79,9 +90,7 @@ void env_destroy();
* ENV_INVALID, the variable name or mode was invalid
*/
int env_set( const wchar_t *key,
const wchar_t *val,
int mode );
int env_set(const wcstring &key, const wchar_t *val, int mode);
/**
@@ -91,7 +100,40 @@ int env_set( const wchar_t *key,
valid until the next call to env_get(), env_set(), env_push() or
env_pop() takes place.
*/
wchar_t *env_get( const wchar_t *key );
//const wchar_t *env_get( const wchar_t *key );
class env_var_t : public wcstring {
private:
bool is_missing;
public:
static env_var_t missing_var(void);
env_var_t(const env_var_t &x) : wcstring(x), is_missing(x.is_missing) { }
env_var_t(const wcstring & x) : wcstring(x), is_missing(false) { }
env_var_t(const wchar_t *x) : wcstring(x), is_missing(false) { }
env_var_t() : wcstring(L""), is_missing(false) { }
bool missing(void) const { return is_missing; }
bool missing_or_empty(void) const { return missing() || empty(); }
const wchar_t *c_str(void) const;
env_var_t &operator=(const env_var_t &s) {
is_missing = s.is_missing;
wcstring::operator=(s);
return *this;
}
bool operator==(const env_var_t &s) const {
if (is_missing && s.is_missing)
return true;
else if (s.is_missing || s.is_missing)
return false;
else
return *static_cast<const wcstring *>(this) == *static_cast<const wcstring *>(&s);
}
};
/**
Gets the variable with the specified name, or an empty string if it does not exist.
*/
env_var_t env_get_string( const wcstring &key );
/**
Returns 1 if the specified key exists. This can't be reliably done
@@ -110,7 +152,7 @@ int env_exist( const wchar_t *key, int mode );
\return zero if the variable existed, and non-zero if the variable did not exist
*/
int env_remove( const wchar_t *key, int mode );
int env_remove( const wcstring &key, int mode );
/**
Push the variable stack. Used for implementing local variables for functions and for-loops.
@@ -122,14 +164,44 @@ void env_push( int new_scope );
*/
void env_pop();
/**
Returns an array containing all exported variables in a format suitable for execv.
*/
char **env_export_arr( int recalc );
/** Returns an array containing all exported variables in a format suitable for execv. */
char **env_export_arr( bool recalc );
void env_export_arr(bool recalc, null_terminated_array_t<char> &result);
/**
Insert all variable names into l. These are not copies of the strings and should not be freed after use.
Returns all variable names.
*/
void env_get_names( array_list_t *l, int flags );
wcstring_list_t env_get_names( int flags );
/**
Update the PWD variable
directory
*/
int env_set_pwd();
class env_vars_snapshot_t {
std::map<wcstring, wcstring> vars;
bool is_current() const;
public:
env_vars_snapshot_t(const wchar_t * const * keys);
env_vars_snapshot_t(void);
env_var_t get(const wcstring &key) const;
// Returns the fake snapshot representing the live variables array
static const env_vars_snapshot_t &current();
// vars necessary for highlighting
static const wchar_t * const highlighting_keys[];
};
extern bool g_log_forks;
extern int g_fork_count;
extern bool g_use_posix_spawn;
#endif

View File

@@ -61,7 +61,7 @@ static int get_socket_count = 0;
static wchar_t * path;
static wchar_t *user;
static void (*start_fishd)();
static void (*external_callback)( int type, const wchar_t *name, const wchar_t *val );
static void (*external_callback)( fish_message_type_t type, const wchar_t *name, const wchar_t *val );
/**
Flag set to 1 when a barrier reply is recieved
@@ -113,7 +113,7 @@ static int get_socket( int fork_ok )
uname = strdup( pw->pw_name );
}
name = malloc( strlen(dir) +
name = (char *)malloc( strlen(dir) +
strlen(uname) +
strlen(SOCK_FILENAME) +
2 );
@@ -165,7 +165,7 @@ static int get_socket( int fork_ok )
/**
Callback function used whenever a new fishd message is recieved
*/
static void callback( int type, const wchar_t *name, const wchar_t *val )
static void callback( fish_message_type_t type, const wchar_t *name, const wchar_t *val )
{
if( type == BARRIER_REPLY )
{
@@ -198,7 +198,7 @@ static void check_connection()
env_universal_server.fd = -1;
env_universal_server.killme=0;
env_universal_server.input.used=0;
env_universal_server.input.clear();
env_universal_read_all();
}
}
@@ -208,22 +208,17 @@ static void check_connection()
*/
static void env_universal_remove_all()
{
array_list_t lst;
int i;
size_t i;
al_init( &lst );
env_universal_common_get_names( &lst,
wcstring_list_t lst;
env_universal_common_get_names( lst,
1,
1 );
for( i=0; i<al_get_count( &lst ); i++ )
for( i=0; i<lst.size(); i++ )
{
wchar_t *key = (wchar_t *)al_get( &lst, i );
const wcstring &key = lst.at(i);
env_universal_common_remove( key );
}
al_destroy( &lst );
}
@@ -255,7 +250,7 @@ static void reconnect()
void env_universal_init( wchar_t * p,
wchar_t *u,
void (*sf)(),
void (*cb)( int type, const wchar_t *name, const wchar_t *val ))
void (*cb)( fish_message_type_t type, const wchar_t *name, const wchar_t *val ))
{
path=p;
user=u;
@@ -323,28 +318,25 @@ int env_universal_read_all()
}
}
wchar_t *env_universal_get( const wchar_t *name )
wchar_t *env_universal_get( const wcstring &name )
{
if( !init)
return 0;
CHECK( name, 0 );
return env_universal_common_get( name );
}
int env_universal_get_export( const wchar_t *name )
int env_universal_get_export( const wcstring &name )
{
if( !init)
return 0;
CHECK( name, 0 );
return env_universal_common_get_export( name );
}
void env_universal_barrier()
{
ASSERT_IS_MAIN_THREAD();
message_t *msg;
fd_set fds;
@@ -358,7 +350,7 @@ void env_universal_barrier()
*/
msg= create_message( BARRIER, 0, 0);
msg->count=1;
q_put( &env_universal_server.unsent, msg );
env_universal_server.unsent->push(msg);
/*
Wait until barrier request has been sent
@@ -369,7 +361,7 @@ void env_universal_barrier()
try_send_all( &env_universal_server );
check_connection();
if( q_empty( &env_universal_server.unsent ) )
if( env_universal_server.unsent->empty() )
break;
if( env_universal_server.fd == -1 )
@@ -405,26 +397,24 @@ void env_universal_barrier()
}
void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
void env_universal_set( const wcstring &name, const wcstring &value, int exportv )
{
message_t *msg;
if( !init )
return;
CHECK( name, );
debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name, value );
debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str() );
if( is_dead() )
{
env_universal_common_set( name, value, export );
env_universal_common_set( name.c_str(), value.c_str(), exportv );
}
else
{
msg = create_message( export?SET_EXPORT:SET,
name,
value);
msg = create_message( exportv?SET_EXPORT:SET,
name.c_str(),
value.c_str());
if( !msg )
{
@@ -433,7 +423,7 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
}
msg->count=1;
q_put( &env_universal_server.unsent, msg );
env_universal_server.unsent->push(msg);
env_universal_barrier();
}
}
@@ -455,29 +445,27 @@ int env_universal_remove( const wchar_t *name )
if( is_dead() )
{
env_universal_common_remove( name );
env_universal_common_remove( wcstring(name) );
}
else
{
msg= create_message( ERASE, name, 0);
msg->count=1;
q_put( &env_universal_server.unsent, msg );
env_universal_server.unsent->push(msg);
env_universal_barrier();
}
return res;
}
void env_universal_get_names( array_list_t *l,
void env_universal_get_names2( wcstring_list_t &lst,
int show_exported,
int show_unexported )
{
if( !init )
return;
CHECK( l, );
env_universal_common_get_names( l,
env_universal_common_get_names( lst,
show_exported,
show_unexported );
}

View File

@@ -17,7 +17,10 @@ extern connection_t env_universal_server;
/**
Initialize the envuni library
*/
void env_universal_init();
void env_universal_init( wchar_t * p,
wchar_t *u,
void (*sf)(),
void (*cb)( fish_message_type_t type, const wchar_t *name, const wchar_t *val ));
/**
Free memory used by envuni
*/
@@ -26,18 +29,18 @@ void env_universal_destroy();
/**
Get the value of a universal variable
*/
wchar_t *env_universal_get( const wchar_t *name );
wchar_t *env_universal_get( const wcstring &name );
/**
Get the export flag of the variable with the specified
name. Returns 0 if the variable doesn't exist.
*/
int env_universal_get_export( const wchar_t *name );
int env_universal_get_export( const wcstring &name );
/**
Set the value of a universal variable
*/
void env_universal_set( const wchar_t *name, const wchar_t *val, int export );
void env_universal_set( const wcstring &name, const wcstring &val, int exportv );
/**
Erase a universal variable
@@ -57,7 +60,7 @@ int env_universal_read_all();
\param show_exported whether exported variables should be shown
\param show_unexported whether unexported variables should be shown
*/
void env_universal_get_names( array_list_t *l,
void env_universal_get_names2( wcstring_list_t &list,
int show_exported,
int show_unexported );

View File

@@ -28,6 +28,7 @@
#include <dirent.h>
#include <signal.h>
#include <sys/stat.h>
#include <map>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -92,42 +93,33 @@
*/
typedef struct var_uni_entry
{
int export; /**< Whether the variable should be exported */
wchar_t val[1]; /**< The value of the variable */
int exportv; /**< Whether the variable should be exported */
wcstring val; /**< The value of the variable */
var_uni_entry():exportv(0), val() { }
}
var_uni_entry_t;
static void parse_message( wchar_t *msg,
connection_t *src );
connection_t *src );
/**
The table of all universal variables
*/
hash_table_t env_universal_var;
typedef std::map<wcstring, var_uni_entry_t*> env_var_table_t;
env_var_table_t env_universal_var;
/**
Callback function, should be called on all events
*/
void (*callback)( int type,
static void (*callback)( fish_message_type_t type,
const wchar_t *key,
const wchar_t *val );
/**
Variable used by env_get_names to communicate auxiliary information
to add_key_to_hash
*/
static int get_names_show_exported;
/**
Variable used by env_get_names to communicate auxiliary information
to add_key_to_hash
*/
static int get_names_show_unexported;
/**
List of names for the UTF-8 character set.
*/
static char *iconv_utf8_names[]=
static const char *iconv_utf8_names[]=
{
"utf-8", "UTF-8",
"utf8", "UTF8",
@@ -138,7 +130,7 @@ static char *iconv_utf8_names[]=
/**
List of wide character names, undefined byte length.
*/
static char *iconv_wide_names_unknown[]=
static const char *iconv_wide_names_unknown[]=
{
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
@@ -149,7 +141,7 @@ static char *iconv_wide_names_unknown[]=
/**
List of wide character names, 4 bytes long.
*/
static char *iconv_wide_names_4[]=
static const char *iconv_wide_names_4[]=
{
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
@@ -164,7 +156,7 @@ static char *iconv_wide_names_4[]=
/**
List of wide character names, 2 bytes long.
*/
static char *iconv_wide_names_2[]=
static const char *iconv_wide_names_2[]=
{
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
@@ -176,8 +168,30 @@ static char *iconv_wide_names_2[]=
}
;
template<class T>
class sloppy {};
wchar_t *utf2wcs( const char *in )
static size_t hack_iconv(iconv_t cd, const char * const* inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
{
/* FreeBSD has this prototype: size_t iconv (iconv_t, const char **...)
OS X and Linux this one: size_t iconv (iconv_t, char **...)
AFAIK there's no single type that can be passed as both char ** and const char **.
Therefore, we let C++ figure it out, by providing a struct with an implicit conversion to both char** and const char **.
*/
struct sloppy_char
{
const char * const * t;
operator char** () const { return (char **)t; }
operator const char** () const { return (const char**)t; }
} slop_inbuf = {inbuf};
return iconv( cd, slop_inbuf, inbytesleft, outbuf, outbytesleft );
}
/**
Convert utf-8 string to wide string
*/
static wchar_t *utf2wcs( const char *in )
{
iconv_t cd=(iconv_t) -1;
int i,j;
@@ -190,7 +204,7 @@ wchar_t *utf2wcs( const char *in )
really the character set used by wchar_t, but it is the best
assumption we can make.
*/
char **to_name=0;
const char **to_name=0;
switch (sizeof (wchar_t))
{
@@ -212,14 +226,14 @@ wchar_t *utf2wcs( const char *in )
/*
The line protocol fish uses is always utf-8.
*/
char **from_name = iconv_utf8_names;
const char **from_name = iconv_utf8_names;
size_t in_len = strlen( in );
size_t out_len = sizeof( wchar_t )*(in_len+2);
size_t nconv;
char *nout;
out = malloc( out_len );
out = (wchar_t *)malloc( out_len );
nout = (char *)out;
if( !out )
@@ -253,7 +267,12 @@ wchar_t *utf2wcs( const char *in )
return 0;
}
nconv = iconv( cd, (const char **)&in, &in_len, &nout, &out_len );
/* FreeBSD has this prototype: size_t iconv (iconv_t, const char **...)
OS X and Linux this one: size_t iconv (iconv_t, char **...)
AFAIK there's no single type that can be passed as both char ** and const char **.
So we cast the function pointer instead (!)
*/
nconv = hack_iconv( cd, &in, &in_len, &nout, &out_len );
if (nconv == (size_t) -1)
{
@@ -287,7 +306,12 @@ wchar_t *utf2wcs( const char *in )
return out;
}
char *wcs2utf( const wchar_t *in )
/**
Convert wide string to utf-8
*/
static char *wcs2utf( const wchar_t *in )
{
iconv_t cd=(iconv_t) -1;
int i,j;
@@ -301,7 +325,7 @@ char *wcs2utf( const wchar_t *in )
really the character set used by wchar_t, but it is the best
assumption we can make.
*/
char **from_name=0;
const char **from_name=0;
switch (sizeof (wchar_t))
{
@@ -319,14 +343,14 @@ char *wcs2utf( const wchar_t *in )
break;
}
char **to_name = iconv_utf8_names;
const char **to_name = iconv_utf8_names;
size_t in_len = wcslen( in );
size_t out_len = sizeof( char )*( (MAX_UTF8_BYTES*in_len)+1);
size_t nconv;
char *nout;
out = malloc( out_len );
out = (char *)malloc( out_len );
nout = (char *)out;
in_len *= sizeof( wchar_t );
@@ -361,7 +385,7 @@ char *wcs2utf( const wchar_t *in )
return 0;
}
nconv = iconv( cd, &char_in, &in_len, &nout, &out_len );
nconv = hack_iconv( cd, &char_in, &in_len, &nout, &out_len );
if (nconv == (size_t) -1)
@@ -381,38 +405,33 @@ char *wcs2utf( const wchar_t *in )
void env_universal_common_init( void (*cb)(int type, const wchar_t *key, const wchar_t *val ) )
void env_universal_common_init( void (*cb)(fish_message_type_t type, const wchar_t *key, const wchar_t *val ) )
{
callback = cb;
hash_init( &env_universal_var, &hash_wcs_func, &hash_wcs_cmp );
}
/**
Free both key and data
*/
static void erase( void *key,
void *data )
{
free( (void *)key );
free( (void *)data );
}
void env_universal_common_destroy()
{
hash_foreach( &env_universal_var, &erase );
hash_destroy( &env_universal_var );
env_var_table_t::iterator iter;
for(iter = env_universal_var.begin(); iter != env_universal_var.end(); ++iter)
{
var_uni_entry_t* value = iter->second;
delete value;
}
}
/**
Read one byte of date form the specified connection
*/
static int read_byte( connection_t *src )
{
if( src->buffer_consumed >= src->buffer_used )
{
int res;
res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
ssize_t res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
// debug(4, L"Read chunk '%.*s'", res, src->buffer );
@@ -471,13 +490,13 @@ void read_message( connection_t *src )
{
src->killme = 1;
debug( 3, L"Fd %d has reached eof, set killme flag", src->fd );
if( src->input.used > 0 )
if( src->input.size() > 0 )
{
char c = 0;
b_append( &src->input, &c, 1 );
src->input.push_back(c);
debug( 1,
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
(wchar_t *)src->input.buff );
&src->input.at(0));
}
return;
}
@@ -490,16 +509,16 @@ void read_message( connection_t *src )
wchar_t *msg;
b = 0;
b_append( &src->input, &b, 1 );
src->input.push_back(b);
msg = utf2wcs( src->input.buff );
msg = utf2wcs( &src->input.at(0) );
/*
Before calling parse_message, we must empty reset
everything, since the callback function could
potentially call read_message.
*/
src->input.used=0;
src->input.clear();
if( msg )
{
@@ -507,7 +526,7 @@ void read_message( connection_t *src )
}
else
{
debug( 0, _(L"Could not convert message '%s' to wide character string"), src->input.buff );
debug( 0, _(L"Could not convert message '%s' to wide character string"), &src->input.at(0) );
}
free( msg );
@@ -515,7 +534,7 @@ void read_message( connection_t *src )
}
else
{
b_append( &src->input, &b, 1 );
src->input.push_back(b);
}
}
}
@@ -523,15 +542,15 @@ void read_message( connection_t *src )
/**
Remove variable with specified name
*/
void env_universal_common_remove( const wchar_t *name )
void env_universal_common_remove( const wcstring &name )
{
void *k, *v;
hash_remove( &env_universal_var,
name,
&k,
&v );
free( k );
free( v );
env_var_table_t::iterator result = env_universal_var.find(name);
if (result != env_universal_var.end())
{
var_uni_entry_t* v = result->second;
env_universal_var.erase(result);
delete v;
}
}
/**
@@ -549,30 +568,23 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
return 1;
}
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export )
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int exportv )
{
var_uni_entry_t *entry;
wchar_t *name;
CHECK( key, );
CHECK( val, );
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
name = wcsdup(key);
entry = new var_uni_entry_t;
entry->exportv=exportv;
entry->val = val;
env_universal_common_remove( key );
if( !entry || !name )
DIE_MEM();
entry->export=export;
wcscpy( entry->val, val );
env_universal_common_remove( name );
hash_put( &env_universal_var, name, entry );
env_universal_var[key] = entry;
if( callback )
{
callback( export?SET_EXPORT:SET, name, val );
callback( exportv?SET_EXPORT:SET, key, val );
}
}
@@ -580,7 +592,7 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
/**
Parse message msg
*/
static void parse_message( wchar_t *msg,
static void parse_message( wchar_t *msg,
connection_t *src )
{
// debug( 3, L"parse_message( %ls );", msg );
@@ -591,9 +603,9 @@ static void parse_message( wchar_t *msg,
if( match( msg, SET_STR ) || match( msg, SET_EXPORT_STR ))
{
wchar_t *name, *tmp;
int export = match( msg, SET_EXPORT_STR );
int exportv = match( msg, SET_EXPORT_STR );
name = msg+(export?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
name = msg+(exportv?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
while( wcschr( L"\t ", *name ) )
name++;
@@ -603,14 +615,15 @@ static void parse_message( wchar_t *msg,
wchar_t *key;
wchar_t *val;
key = malloc( sizeof( wchar_t)*(tmp-name+1));
key = (wchar_t *)malloc( sizeof( wchar_t)*(tmp-name+1));
memcpy( key, name, sizeof( wchar_t)*(tmp-name));
key[tmp-name]=0;
val = tmp+1;
val = unescape( val, 0 );
env_universal_common_set( key, val, export );
if (key && val)
env_universal_common_set( key, val, exportv );
free( val );
free( key );
@@ -650,7 +663,7 @@ static void parse_message( wchar_t *msg,
{
message_t *msg = create_message( BARRIER_REPLY, 0, 0 );
msg->count = 1;
q_put( &src->unsent, msg );
src->unsent->push(msg);
try_send_all( src );
}
else if( match( msg, BARRIER_REPLY_STR ) )
@@ -676,17 +689,17 @@ static int try_send( message_t *msg,
{
debug( 3,
L"before write of %d chars to fd %d", strlen(msg->body), fd );
L"before write of %d chars to fd %d", msg->body.size(), fd );
int res = write( fd, msg->body, strlen(msg->body) );
ssize_t res = write( fd, msg->body.c_str(), msg->body.size() );
if( res != -1 )
{
debug( 4, L"Wrote message '%s'", msg->body );
debug( 4, L"Wrote message '%s'", msg->body.c_str() );
}
else
{
debug( 4, L"Failed to write message '%s'", msg->body );
debug( 4, L"Failed to write message '%s'", msg->body.c_str() );
}
if( res == -1 )
@@ -710,7 +723,7 @@ static int try_send( message_t *msg,
if( !msg->count )
{
free( msg );
delete msg;
}
return 1;
}
@@ -720,12 +733,12 @@ void try_send_all( connection_t *c )
/* debug( 3,
L"Send all updates to connection on fd %d",
c->fd );*/
while( !q_empty( &c->unsent) )
while( !c->unsent->empty() )
{
switch( try_send( (message_t *)q_peek( &c->unsent), c->fd ) )
switch( try_send( c->unsent->front(), c->fd ) )
{
case 1:
q_get( &c->unsent);
c->unsent->pop();
break;
case 0:
@@ -740,43 +753,77 @@ void try_send_all( connection_t *c )
}
}
static wchar_t *full_escape( const wchar_t *in )
/* The universal variable format has some funny escaping requirements; here we try to be safe */
static bool is_universal_safe_to_encode_directly(wchar_t c)
{
string_buffer_t out;
sb_init( &out );
if (c < 32 || c > 128)
return false;
return iswalnum(c) || wcschr(L"/", c);
}
/**
Escape specified string
*/
static wcstring full_escape( const wchar_t *in )
{
wcstring out;
for( ; *in; in++ )
{
if( *in < 32 )
wchar_t c = *in;
if (is_universal_safe_to_encode_directly(c))
{
out.push_back(c);
}
else if (c < 256)
{
sb_printf( &out, L"\\x%.2x", *in );
append_format(out, L"\\x%.2x", c);
}
else if( *in < 128 )
else if (c < 65536)
{
sb_append_char( &out, *in );
}
else if( *in < 65536 )
{
sb_printf( &out, L"\\u%.4x", *in );
append_format(out, L"\\u%.4x", c);
}
else
{
sb_printf( &out, L"\\U%.8x", *in );
append_format(out, L"\\U%.8x", c);
}
}
return (wchar_t *)out.buff;
return out;
}
message_t *create_message( int type,
const wchar_t *key_in,
const wchar_t *val_in )
/* Sets the body of a message to the null-terminated list of null terminated const char *. */
void set_body(message_t *msg, ...)
{
message_t *msg=0;
/* Start by counting the length of all the strings */
size_t body_len = 0;
const char *arg;
va_list arg_list;
va_start(arg_list, msg);
while ((arg = va_arg(arg_list, const char *)) != NULL)
body_len += strlen(arg);
va_end(arg_list);
/* Reserve that length in the string */
msg->body.reserve(body_len + 1); //+1 for trailing NULL? Do I need that?
/* Set the string contents */
va_start(arg_list, msg);
while ((arg = va_arg(arg_list, const char *)) != NULL)
msg->body.append(arg);
va_end(arg_list);
}
/* Returns an instance of message_t allocated via new */
message_t *create_message( fish_message_type_t type,
const wchar_t *key_in,
const wchar_t *val_in )
{
message_t *msg = new message_t;
msg->count = 0;
char *key=0;
size_t sz;
// debug( 4, L"Crete message of type %d", type );
// debug( 4, L"Crete message of type %d", type );
if( key_in )
{
@@ -790,8 +837,8 @@ message_t *create_message( int type,
if( !key )
{
debug( 0,
L"Could not convert %ls to narrow character string",
key_in );
L"Could not convert %ls to narrow character string",
key_in );
return 0;
}
}
@@ -807,152 +854,108 @@ message_t *create_message( int type,
val_in=L"";
}
wchar_t *esc = full_escape( val_in );
if( !esc )
break;
char *val = wcs2utf(esc );
free(esc);
sz = strlen(type==SET?SET_MBS:SET_EXPORT_MBS) + strlen(key) + strlen(val) + 4;
msg = malloc( sizeof( message_t ) + sz );
if( !msg )
DIE_MEM();
strcpy( msg->body, (type==SET?SET_MBS:SET_EXPORT_MBS) );
strcat( msg->body, " " );
strcat( msg->body, key );
strcat( msg->body, ":" );
strcat( msg->body, val );
strcat( msg->body, "\n" );
wcstring esc = full_escape( val_in );
char *val = wcs2utf(esc.c_str());
set_body(msg, (type==SET?SET_MBS:SET_EXPORT_MBS), " ", key, ":", val, "\n", NULL);
free( val );
break;
}
case ERASE:
{
sz = strlen(ERASE_MBS) + strlen(key) + 3;
msg = malloc( sizeof( message_t ) + sz );
if( !msg )
DIE_MEM();
strcpy( msg->body, ERASE_MBS " " );
strcat( msg->body, key );
strcat( msg->body, "\n" );
set_body(msg, ERASE_MBS, " ", key, "\n", NULL);
break;
}
case BARRIER:
{
msg = malloc( sizeof( message_t ) +
strlen( BARRIER_MBS ) +2);
if( !msg )
DIE_MEM();
strcpy( msg->body, BARRIER_MBS "\n" );
set_body(msg, BARRIER_MBS, "\n", NULL);
break;
}
case BARRIER_REPLY:
{
msg = malloc( sizeof( message_t ) +
strlen( BARRIER_REPLY_MBS ) +2);
if( !msg )
DIE_MEM();
strcpy( msg->body, BARRIER_REPLY_MBS "\n" );
set_body(msg, BARRIER_REPLY_MBS, "\n", NULL);
break;
}
default:
{
debug( 0, L"create_message: Unknown message type" );
}
}
free( key );
if( msg )
msg->count=0;
// debug( 4, L"Message body is '%s'", msg->body );
// debug( 4, L"Message body is '%s'", msg->body );
return msg;
}
/**
Function used with hash_foreach to insert keys of one table into
another
*/
static void add_key_to_hash( void *key,
void *data,
void *aux )
{
var_uni_entry_t *e = (var_uni_entry_t *)data;
if( ( e->export && get_names_show_exported) ||
( !e->export && get_names_show_unexported) )
al_push( (array_list_t *)aux, key );
}
void env_universal_common_get_names( array_list_t *l,
Put exported or unexported variables in a string list
*/
void env_universal_common_get_names( wcstring_list_t &lst,
int show_exported,
int show_unexported )
{
get_names_show_exported = show_exported;
get_names_show_unexported = show_unexported;
env_var_table_t::const_iterator iter;
for (iter = env_universal_var.begin(); iter != env_universal_var.end(); ++iter)
{
const wcstring& key = iter->first;
const var_uni_entry_t *e = iter->second;
if( ( e->exportv && show_exported) ||
( !e->exportv && show_unexported) )
{
lst.push_back(key);
}
hash_foreach2( &env_universal_var,
add_key_to_hash,
l );
}
}
wchar_t *env_universal_common_get( const wchar_t *name )
wchar_t *env_universal_common_get( const wcstring &name )
{
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
if( e )
return e->val;
env_var_table_t::const_iterator result = env_universal_var.find(name);
if (result != env_universal_var.end() )
{
const var_uni_entry_t *e = result->second;
if( e )
return const_cast<wchar_t*>(e->val.c_str());
}
return 0;
}
int env_universal_common_get_export( const wchar_t *name )
int env_universal_common_get_export( const wcstring &name )
{
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
if( e )
return e->export;
env_var_table_t::const_iterator result = env_universal_var.find(name);
if (result != env_universal_var.end() )
{
const var_uni_entry_t *e = result->second;
if (e != NULL)
return e->exportv;
}
return 0;
}
/**
Adds a variable creation message about the specified variable to
the specified queue. The function signature is non-obvious since
this function is used together with hash_foreach2, which requires
the specified function signature.
\param k the variable name
\param v the variable value
\param q the queue to add the message to
*/
static void enqueue( void *k,
void *v,
void *q)
{
const wchar_t *key = (const wchar_t *)k;
const var_uni_entry_t *val = (const var_uni_entry_t *)v;
dyn_queue_t *queue = (dyn_queue_t *)q;
message_t *msg = create_message( val->export?SET_EXPORT:SET, key, val->val );
msg->count=1;
q_put( queue, msg );
}
void enqueue_all( connection_t *c )
{
hash_foreach2( &env_universal_var,
&enqueue,
(void *)&c->unsent );
env_var_table_t::const_iterator iter;
for (iter = env_universal_var.begin(); iter != env_universal_var.end(); ++iter)
{
const wcstring &key = iter->first;
const var_uni_entry_t *val = iter->second;
message_t *msg = create_message( val->exportv?SET_EXPORT:SET, key.c_str(), val->val.c_str() );
msg->count=1;
c->unsent->push(msg);
}
try_send_all( c );
}
@@ -961,15 +964,13 @@ void connection_init( connection_t *c, int fd )
{
memset (c, 0, sizeof (connection_t));
c->fd = fd;
b_init( &c->input );
q_init( &c->unsent );
c->unsent = new std::queue<message_t *>;
c->buffer_consumed = c->buffer_used = 0;
}
void connection_destroy( connection_t *c)
{
q_destroy( &c->unsent );
b_destroy( &c->input );
if (c->unsent) delete c->unsent;
/*
A connection need not always be open - we only try to close it

View File

@@ -2,7 +2,8 @@
#define FISH_ENV_UNIVERSAL_COMMON_H
#include <wchar.h>
#include <queue>
#include <string>
#include "util.h"
/**
@@ -39,21 +40,39 @@
/**
The different types of commands that can be sent between client/server
*/
enum
typedef enum
{
SET,
SET_EXPORT,
ERASE,
BARRIER,
BARRIER_REPLY,
}
;
} fish_message_type_t;
/**
The size of the buffer used for reading from the socket
*/
#define ENV_UNIVERSAL_BUFFER_SIZE 1024
/**
A struct representing a message to be sent between client and server
*/
typedef struct
{
/**
Number of queues that contain this message. Once this reaches zero, the message should be deleted
*/
int count;
/**
Message body. The message must be allocated using enough memory to actually contain the message.
*/
std::string body;
} message_t;
typedef std::queue<message_t *> message_queue_t;
/**
This struct represents a connection between a universal variable server/client
*/
@@ -66,7 +85,7 @@ typedef struct connection
/**
Queue of onsent messages
*/
dyn_queue_t unsent;
message_queue_t *unsent;
/**
Set to one when this connection should be killed
*/
@@ -75,7 +94,7 @@ typedef struct connection
The input string. Input from the socket goes here. When a
newline is encountered, the buffer is parsed and cleared.
*/
buffer_t input;
std::vector<char> input;
/**
The read buffer.
@@ -85,12 +104,12 @@ typedef struct connection
/**
Number of bytes that have already been consumed.
*/
int buffer_consumed;
size_t buffer_consumed;
/**
Number of bytes that have been read into the buffer.
*/
int buffer_used;
size_t buffer_used;
/**
@@ -100,22 +119,6 @@ typedef struct connection
}
connection_t;
/**
A struct representing a message to be sent between client and server
*/
typedef struct
{
/**
Number of queues that contain this message. Once this reaches zero, the message should be deleted
*/
int count;
/**
Message body. The message must be allocated using enough memory to actually contain the message.
*/
char body[1];
}
message_t;
/**
Read all available messages on this connection
*/
@@ -129,12 +132,12 @@ void try_send_all( connection_t *c );
/**
Create a messge with the specified properties
*/
message_t *create_message( int type, const wchar_t *key, const wchar_t *val );
message_t *create_message( fish_message_type_t type, const wchar_t *key, const wchar_t *val );
/**
Init the library
*/
void env_universal_common_init(void (*cb)(int type, const wchar_t *key, const wchar_t *val ) );
void env_universal_common_init(void (*cb)(fish_message_type_t type, const wchar_t *key, const wchar_t *val ) );
/**
Destroy library data
@@ -147,7 +150,7 @@ void env_universal_common_destroy();
This function operate agains the local copy of all universal
variables, it does not communicate with any other process.
*/
void env_universal_common_get_names( array_list_t *l,
void env_universal_common_get_names( wcstring_list_t &lst,
int show_exported,
int show_unexported );
@@ -160,7 +163,7 @@ void env_universal_common_get_names( array_list_t *l,
Do not call this function. Create a message to do it. This function
is only to be used when fishd is dead.
*/
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export );
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int exportv );
/**
Remove the specified variable.
@@ -171,7 +174,7 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
Do not call this function. Create a message to do it. This function
is only to be used when fishd is dead.
*/
void env_universal_common_remove( const wchar_t *key );
void env_universal_common_remove( const wcstring &key );
/**
Get the value of the variable with the specified name
@@ -179,7 +182,7 @@ void env_universal_common_remove( const wchar_t *key );
This function operate agains the local copy of all universal
variables, it does not communicate with any other process.
*/
wchar_t *env_universal_common_get( const wchar_t *name );
wchar_t *env_universal_common_get( const wcstring &name );
/**
Get the export flag of the variable with the specified
@@ -188,7 +191,7 @@ wchar_t *env_universal_common_get( const wchar_t *name );
This function operate agains the local copy of all universal
variables, it does not communicate with any other process.
*/
int env_universal_common_get_export( const wchar_t *name );
int env_universal_common_get_export( const wcstring &name );
/**
Add messages about all existing variables to the specified connection

View File

@@ -1,7 +1,6 @@
#
# Init file for fish
#
# @configure_input@
#
# Some things should only be done for login terminals
@@ -38,17 +37,6 @@ if status --is-login
end
end
#
# There are variables that contain colons that are not arrays. This
# reverts them back to regular strings.
#
for i in DISPLAY
if set -q $i
set -- $i (printf ":%s" $$i|cut -c 2-)
end
end
#
# Load additional initialization files
#

722
event.c
View File

@@ -1,722 +0,0 @@
/** \file event.c
Functions for handling event triggers
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <unistd.h>
#include <termios.h>
#include <signal.h>
#include <string.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "function.h"
#include "proc.h"
#include "parser.h"
#include "common.h"
#include "event.h"
#include "signal.h"
#include "halloc_util.h"
/**
Number of signals that can be queued before an overflow occurs
*/
#define SIG_UNHANDLED_MAX 64
/**
This struct contains a list of generated signals waiting to be
dispatched
*/
typedef struct
{
/**
Number of delivered signals
*/
int count;
/**
Whether signals have been skipped
*/
int overflow;
/**
Array of signal events
*/
int signal[SIG_UNHANDLED_MAX];
}
signal_list_t;
/**
The signal event list. Actually two separate lists. One which is
active, which is the one that new events is written to. The inactive
one contains the events that are currently beeing performed.
*/
static signal_list_t sig_list[]={{0,0},{0,0}};
/**
The index of sig_list that is the list of signals currently written to
*/
static int active_list=0;
/**
List of event handlers
*/
static array_list_t *events;
/**
List of event handlers that should be removed
*/
static array_list_t *killme;
/**
List of events that have been sent but have not yet been delivered because they are blocked.
*/
static array_list_t *blocked;
/**
Tests if one event instance matches the definition of a event
class. If both the class and the instance name a function,
they must name the same function.
*/
static int event_match( event_t *class, event_t *instance )
{
if( class->function_name && instance->function_name )
{
if( wcscmp( class->function_name, instance->function_name ) != 0 )
return 0;
}
if( class->type == EVENT_ANY )
return 1;
if( class->type != instance->type )
return 0;
switch( class->type )
{
case EVENT_SIGNAL:
if( class->param1.signal == EVENT_ANY_SIGNAL )
return 1;
return class->param1.signal == instance->param1.signal;
case EVENT_VARIABLE:
return wcscmp( instance->param1.variable,
class->param1.variable )==0;
case EVENT_EXIT:
if( class->param1.pid == EVENT_ANY_PID )
return 1;
return class->param1.pid == instance->param1.pid;
case EVENT_JOB_ID:
return class->param1.job_id == instance->param1.job_id;
case EVENT_GENERIC:
return wcscmp( instance->param1.param,
class->param1.param )==0;
}
/**
This should never be reached
*/
return 0;
}
/**
Create an identical copy of an event. Use deep copying, i.e. make
duplicates of any strings used as well.
*/
static event_t *event_copy( event_t *event, int copy_arguments )
{
event_t *e = malloc( sizeof( event_t ) );
if( !e )
DIE_MEM();
memcpy( e, event, sizeof(event_t));
if( e->function_name )
e->function_name = wcsdup( e->function_name );
if( e->type == EVENT_VARIABLE )
e->param1.variable = wcsdup( e->param1.variable );
else if( e->type == EVENT_GENERIC )
e->param1.param = wcsdup( e->param1.param );
al_init( &e->arguments );
if( copy_arguments )
{
int i;
for( i=0; i<al_get_count( &event->arguments ); i++ )
{
al_push( &e->arguments, wcsdup( (wchar_t *)al_get( &event->arguments, i ) ) );
}
}
return e;
}
/**
Test if specified event is blocked
*/
static int event_is_blocked( event_t *e )
{
block_t *block;
event_block_t *eb;
for( block = current_block; block; block = block->outer )
{
for( eb = block->first_event_block; eb; eb=eb->next )
{
if( eb->type & (1<<EVENT_ANY ) )
return 1;
if( eb->type & (1<<e->type) )
return 1;
}
}
for( eb = global_event_block; eb; eb=eb->next )
{
if( eb->type & (1<<EVENT_ANY ) )
return 1;
if( eb->type & (1<<e->type) )
return 1;
return 1;
}
return 0;
}
const wchar_t *event_get_desc( event_t *e )
{
/*
String buffer used for formating event descriptions in event_get_desc()
*/
static string_buffer_t *get_desc_buff=0;
CHECK( e, 0 );
if( !get_desc_buff )
{
get_desc_buff=sb_halloc( global_context );
}
else
{
sb_clear( get_desc_buff );
}
switch( e->type )
{
case EVENT_SIGNAL:
sb_printf( get_desc_buff, _(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ) );
break;
case EVENT_VARIABLE:
sb_printf( get_desc_buff, _(L"handler for variable '%ls'"), e->param1.variable );
break;
case EVENT_EXIT:
if( e->param1.pid > 0 )
{
sb_printf( get_desc_buff, _(L"exit handler for process %d"), e->param1.pid );
}
else
{
job_t *j = job_get_from_pid( -e->param1.pid );
if( j )
sb_printf( get_desc_buff, _(L"exit handler for job %d, '%ls'"), j->job_id, j->command );
else
sb_printf( get_desc_buff, _(L"exit handler for job with process group %d"), -e->param1.pid );
}
break;
case EVENT_JOB_ID:
{
job_t *j = job_get( e->param1.job_id );
if( j )
sb_printf( get_desc_buff, _(L"exit handler for job %d, '%ls'"), j->job_id, j->command );
else
sb_printf( get_desc_buff, _(L"exit handler for job with job id %d"), j->job_id );
break;
}
case EVENT_GENERIC:
sb_printf( get_desc_buff, _(L"handler for generic event '%ls'"), e->param1.param );
break;
default:
sb_printf( get_desc_buff, _(L"Unknown event type") );
break;
}
return (const wchar_t *)get_desc_buff->buff;
}
void event_add_handler( event_t *event )
{
event_t *e;
CHECK( event, );
e = event_copy( event, 0 );
if( !events )
events = al_new();
if( e->type == EVENT_SIGNAL )
{
signal_handle( e->param1.signal, 1 );
}
al_push( events, e );
}
void event_remove( event_t *criterion )
{
int i;
array_list_t *new_list=0;
event_t e;
CHECK( criterion, );
/*
Because of concurrency issues (env_remove could remove an event
that is currently being executed), env_remove does not actually
free any events - instead it simply moves all events that should
be removed from the event list to the killme list, and the ones
that shouldn't be killed to new_list, and then drops the empty
events-list.
*/
if( !events )
return;
for( i=0; i<al_get_count( events); i++ )
{
event_t *n = (event_t *)al_get( events, i );
if( event_match( criterion, n ) )
{
if( !killme )
killme = al_new();
al_push( killme, n );
/*
If this event was a signal handler and no other handler handles
the specified signal type, do not handle that type of signal any
more.
*/
if( n->type == EVENT_SIGNAL )
{
e.type = EVENT_SIGNAL;
e.param1.signal = n->param1.signal;
e.function_name = 0;
if( event_get( &e, 0 ) == 1 )
{
signal_handle( e.param1.signal, 0 );
}
}
}
else
{
if( !new_list )
new_list = al_new();
al_push( new_list, n );
}
}
al_destroy( events );
free( events );
events = new_list;
}
int event_get( event_t *criterion, array_list_t *out )
{
int i;
int found = 0;
if( !events )
return 0;
CHECK( criterion, 0 );
for( i=0; i<al_get_count( events); i++ )
{
event_t *n = (event_t *)al_get( events, i );
if( event_match(criterion, n ) )
{
found++;
if( out )
al_push( out, n );
}
}
return found;
}
/**
Free all events in the kill list
*/
static void event_free_kills()
{
int i;
if( !killme )
return;
for( i=0; i<al_get_count( killme ); i++ )
{
event_t *roadkill = (event_t *)al_get( killme, i );
event_free( roadkill );
}
al_truncate( killme, 0 );
}
/**
Test if the specified event is waiting to be killed
*/
static int event_is_killed( event_t *e )
{
int i;
if( !killme )
return 0;
for( i=0; i<al_get_count( killme ); i++ )
{
event_t *roadkill = (event_t *)al_get( events, i );
if( roadkill ==e )
return 1;
}
return 0;
}
/**
Perform the specified event. Since almost all event firings will
not be matched by even a single event handler, we make sure to
optimize the 'no matches' path. This means that nothing is
allocated/initialized unless needed.
*/
static void event_fire_internal( event_t *event )
{
int i, j;
string_buffer_t *b=0;
array_list_t *fire=0;
/*
First we free all events that have been removed
*/
event_free_kills();
if( !events )
return;
/*
Then we iterate over all events, adding events that should be
fired to a second list. We need to do this in a separate step
since an event handler might call event_remove or
event_add_handler, which will change the contents of the \c
events list.
*/
for( i=0; i<al_get_count( events ); i++ )
{
event_t *criterion = (event_t *)al_get( events, i );
/*
Check if this event is a match
*/
if(event_match( criterion, event ) )
{
if( !fire )
fire = al_new();
al_push( fire, criterion );
}
}
/*
No matches. Time to return.
*/
if( !fire )
return;
/*
Iterate over our list of matching events
*/
for( i=0; i<al_get_count( fire ); i++ )
{
event_t *criterion = (event_t *)al_get( fire, i );
int prev_status;
/*
Check if this event has been removed, if so, dont fire it
*/
if( event_is_killed( criterion ) )
continue;
/*
Fire event
*/
if( !b )
b = sb_new();
else
sb_clear( b );
sb_append( b, criterion->function_name );
for( j=0; j<al_get_count(&event->arguments); j++ )
{
wchar_t *arg_esc = escape( (wchar_t *)al_get( &event->arguments, j), 1 );
sb_append( b, L" " );
sb_append( b, arg_esc );
free( arg_esc );
}
// debug( 1, L"Event handler fires command '%ls'", (wchar_t *)b->buff );
/*
Event handlers are not part of the main flow of code, so
they are marked as non-interactive
*/
proc_push_interactive(0);
prev_status = proc_get_last_status();
parser_push_block( EVENT );
current_block->param1.event = event;
eval( (wchar_t *)b->buff, 0, TOP );
parser_pop_block();
proc_pop_interactive();
proc_set_last_status( prev_status );
}
if( b )
{
sb_destroy( b );
free( b );
}
if( fire )
{
al_destroy( fire );
free( fire );
}
/*
Free killed events
*/
event_free_kills();
}
/**
Handle all pending signal events
*/
static void event_fire_delayed()
{
int i;
/*
If is_event is one, we are running the event-handler non-recursively.
When the event handler has called a piece of code that triggers
another event, we do not want to fire delayed events because of
concurrency problems.
*/
if( blocked && is_event==1)
{
array_list_t *new_blocked = 0;
for( i=0; i<al_get_count( blocked ); i++ )
{
event_t *e = (event_t *)al_get( blocked, i );
if( event_is_blocked( e ) )
{
if( !new_blocked )
new_blocked = al_new();
al_push( new_blocked, e );
}
else
{
event_fire_internal( e );
event_free( e );
}
}
al_destroy( blocked );
free( blocked );
blocked = new_blocked;
}
while( sig_list[active_list].count > 0 )
{
signal_list_t *lst;
event_t e;
al_init( &e.arguments );
/*
Switch signal lists
*/
sig_list[1-active_list].count=0;
sig_list[1-active_list].overflow=0;
active_list=1-active_list;
/*
Set up
*/
e.type=EVENT_SIGNAL;
e.function_name=0;
lst = &sig_list[1-active_list];
if( lst->overflow )
{
debug( 0, _( L"Signal list overflow. Signals have been ignored." ) );
}
/*
Send all signals in our private list
*/
for( i=0; i<lst->count; i++ )
{
e.param1.signal = lst->signal[i];
al_set( &e.arguments, 0, sig2wcs( e.param1.signal ) );
if( event_is_blocked( &e ) )
{
if( !blocked )
blocked = al_new();
al_push( blocked, event_copy(&e, 1) );
}
else
{
event_fire_internal( &e );
}
}
al_destroy( &e.arguments );
}
}
void event_fire( event_t *event )
{
is_event++;
if( event && (event->type == EVENT_SIGNAL) )
{
/*
This means we are in a signal handler. We must be very
careful not do do anything that could cause a memory
allocation or something else that might be bad when in a
signal handler.
*/
if( sig_list[active_list].count < SIG_UNHANDLED_MAX )
sig_list[active_list].signal[sig_list[active_list].count++]=event->param1.signal;
else
sig_list[active_list].overflow=1;
}
else
{
/*
Fire events triggered by signals
*/
event_fire_delayed();
if( event )
{
if( event_is_blocked( event ) )
{
if( !blocked )
blocked = al_new();
al_push( blocked, event_copy(event, 1) );
}
else
{
event_fire_internal( event );
}
}
}
is_event--;
}
void event_init()
{
}
void event_destroy()
{
if( events )
{
al_foreach( events, (void (*)(void *))&event_free );
al_destroy( events );
free( events );
events=0;
}
if( killme )
{
al_foreach( killme, (void (*)(void *))&event_free );
al_destroy( killme );
free( killme );
killme=0;
}
}
void event_free( event_t *e )
{
CHECK( e, );
/*
When apropriate, we clear the argument vector
*/
al_foreach( &e->arguments, &free );
al_destroy( &e->arguments );
free( (void *)e->function_name );
if( e->type == EVENT_VARIABLE )
{
free( (void *)e->param1.variable );
}
else if( e->type == EVENT_GENERIC )
{
free( (void *)e->param1.param );
}
free( e );
}
void event_fire_generic(const wchar_t *name)
{
event_t ev;
CHECK( name, );
ev.type = EVENT_GENERIC;
ev.param1.param = name;
ev.function_name=0;
al_init( &ev.arguments );
event_fire( &ev );
}

667
event.cpp Normal file
View File

@@ -0,0 +1,667 @@
/** \file event.c
Functions for handling event triggers
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <unistd.h>
#include <termios.h>
#include <signal.h>
#include <string.h>
#include <algorithm>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "function.h"
#include "proc.h"
#include "parser.h"
#include "common.h"
#include "event.h"
#include "signal.h"
/**
Number of signals that can be queued before an overflow occurs
*/
#define SIG_UNHANDLED_MAX 64
/**
This struct contains a list of generated signals waiting to be
dispatched
*/
typedef struct
{
/**
Number of delivered signals
*/
int count;
/**
Whether signals have been skipped
*/
int overflow;
/**
Array of signal events
*/
int signal[SIG_UNHANDLED_MAX];
}
signal_list_t;
/**
The signal event list. Actually two separate lists. One which is
active, which is the one that new events is written to. The inactive
one contains the events that are currently beeing performed.
*/
static signal_list_t sig_list[]={{0,0},{0,0}};
/**
The index of sig_list that is the list of signals currently written to
*/
static int active_list=0;
typedef std::vector<event_t *> event_list_t;
/**
List of event handlers.
Note this is inspected by our signal handler, so we must block signals around manipulating it.
*/
static event_list_t events;
/**
List of event handlers that should be removed
*/
static event_list_t killme;
/**
List of events that have been sent but have not yet been delivered because they are blocked.
*/
static event_list_t blocked;
/**
Tests if one event instance matches the definition of a event
class. If both the class and the instance name a function,
they must name the same function.
*/
static int event_match( const event_t *classv, const event_t *instance )
{
/* If the function names are both non-empty and different, then it's not a match */
if( ! classv->function_name.empty() &&
! instance->function_name.empty() &&
classv->function_name != instance->function_name)
{
return 0;
}
if( classv->type == EVENT_ANY )
return 1;
if( classv->type != instance->type )
return 0;
switch( classv->type )
{
case EVENT_SIGNAL:
if( classv->param1.signal == EVENT_ANY_SIGNAL )
return 1;
return classv->param1.signal == instance->param1.signal;
case EVENT_VARIABLE:
return instance->str_param1 == classv->str_param1;
case EVENT_EXIT:
if( classv->param1.pid == EVENT_ANY_PID )
return 1;
return classv->param1.pid == instance->param1.pid;
case EVENT_JOB_ID:
return classv->param1.job_id == instance->param1.job_id;
case EVENT_GENERIC:
return instance->str_param1 == classv->str_param1;
}
/**
This should never be reached
*/
return 0;
}
/**
Create an identical copy of an event. Use deep copying, i.e. make
duplicates of any strings used as well.
*/
static event_t *event_copy( const event_t *event, int copy_arguments )
{
event_t *e = new event_t(*event);
e->arguments.reset(new wcstring_list_t);
if( copy_arguments && event->arguments.get() != NULL )
{
*(e->arguments) = *(event->arguments);
}
return e;
}
/**
Test if specified event is blocked
*/
static int event_is_blocked( event_t *e )
{
block_t *block;
parser_t &parser = parser_t::principal_parser();
for( block = parser.current_block; block; block = block->outer )
{
if (event_block_list_blocks_type(block->event_blocks, e->type))
return true;
}
return event_block_list_blocks_type(parser.global_event_blocks, e->type);
}
wcstring event_get_desc( const event_t *e )
{
CHECK( e, 0 );
wcstring result;
switch( e->type )
{
case EVENT_SIGNAL:
result = format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ));
break;
case EVENT_VARIABLE:
result = format_string(_(L"handler for variable '%ls'"), e->str_param1.c_str() );
break;
case EVENT_EXIT:
if( e->param1.pid > 0 )
{
result = format_string(_(L"exit handler for process %d"), e->param1.pid );
}
else
{
job_t *j = job_get_from_pid( -e->param1.pid );
if( j )
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_wcstr() );
else
result = format_string(_(L"exit handler for job with process group %d"), -e->param1.pid );
}
break;
case EVENT_JOB_ID:
{
job_t *j = job_get( e->param1.job_id );
if( j )
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_wcstr() );
else
result = format_string(_(L"exit handler for job with job id %d"), e->param1.job_id );
break;
}
case EVENT_GENERIC:
result = format_string(_(L"handler for generic event '%ls'"), e->str_param1.c_str() );
break;
default:
result = format_string(_(L"Unknown event type") );
break;
}
return result;
}
#if 0
static void show_all_handlers(void) {
puts("event handlers:");
for (event_list_t::const_iterator iter = events.begin(); iter != events.end(); ++iter) {
const event_t *foo = *iter;
wcstring tmp = event_get_desc(foo);
printf(" handler now %ls\n", tmp.c_str());
}
}
#endif
void event_add_handler( const event_t *event )
{
event_t *e;
CHECK( event, );
e = event_copy( event, 0 );
if( e->type == EVENT_SIGNAL )
{
signal_handle( e->param1.signal, 1 );
}
// Block around updating the events vector
signal_block();
events.push_back(e);
signal_unblock();
}
void event_remove( event_t *criterion )
{
size_t i;
event_list_t new_list;
CHECK( criterion, );
/*
Because of concurrency issues (env_remove could remove an event
that is currently being executed), env_remove does not actually
free any events - instead it simply moves all events that should
be removed from the event list to the killme list, and the ones
that shouldn't be killed to new_list, and then drops the empty
events-list.
*/
if( events.empty() )
return;
for( i=0; i<events.size(); i++ )
{
event_t *n = events.at(i);
if( event_match( criterion, n ) )
{
killme.push_back(n);
/*
If this event was a signal handler and no other handler handles
the specified signal type, do not handle that type of signal any
more.
*/
if( n->type == EVENT_SIGNAL )
{
event_t e = event_t::signal_event(n->param1.signal);
if( event_get( &e, 0 ) == 1 )
{
signal_handle( e.param1.signal, 0 );
}
}
}
else
{
new_list.push_back(n);
}
}
signal_block();
events.swap(new_list);
signal_unblock();
}
int event_get( event_t *criterion, std::vector<event_t *> *out )
{
size_t i;
int found = 0;
if( events.empty() )
return 0;
CHECK( criterion, 0 );
for( i=0; i<events.size(); i++ )
{
event_t *n = events.at(i);
if( event_match(criterion, n ) )
{
found++;
if( out )
out->push_back(n);
}
}
return found;
}
bool event_is_signal_observed(int sig)
{
/* We are in a signal handler! Don't allocate memory, etc.
This does what event_match does, except it doesn't require passing in an event_t.
*/
size_t i, max = events.size();
for (i=0; i < max; i++)
{
const event_t *event = events[i];
if (event->type == EVENT_ANY)
{
return true;
}
else if (event->type == EVENT_SIGNAL)
{
if( event->param1.signal == EVENT_ANY_SIGNAL || event->param1.signal == sig)
return true;
}
}
return false;
}
/**
Free all events in the kill list
*/
static void event_free_kills()
{
for_each(killme.begin(), killme.end(), event_free);
killme.resize(0);
}
/**
Test if the specified event is waiting to be killed
*/
static int event_is_killed( event_t *e )
{
return std::find(killme.begin(), killme.end(), e) != killme.end();
}
/**
Perform the specified event. Since almost all event firings will
not be matched by even a single event handler, we make sure to
optimize the 'no matches' path. This means that nothing is
allocated/initialized unless needed.
*/
static void event_fire_internal( const event_t *event )
{
size_t i, j;
event_list_t fire;
/*
First we free all events that have been removed
*/
event_free_kills();
if( events.empty() )
return;
/*
Then we iterate over all events, adding events that should be
fired to a second list. We need to do this in a separate step
since an event handler might call event_remove or
event_add_handler, which will change the contents of the \c
events list.
*/
for( i=0; i<events.size(); i++ )
{
event_t *criterion = events.at(i);
/*
Check if this event is a match
*/
if(event_match( criterion, event ) )
{
fire.push_back(criterion);
}
}
/*
No matches. Time to return.
*/
if( fire.empty() )
return;
/*
Iterate over our list of matching events
*/
for( i=0; i<fire.size(); i++ )
{
event_t *criterion = fire.at(i);
int prev_status;
/*
Check if this event has been removed, if so, dont fire it
*/
if( event_is_killed( criterion ) )
continue;
/*
Fire event
*/
wcstring buffer = criterion->function_name;
if (event->arguments.get())
{
for( j=0; j< event->arguments->size(); j++ )
{
wcstring arg_esc = escape_string( event->arguments->at(j), 1 );
buffer += L" ";
buffer += arg_esc;
}
}
// debug( 1, L"Event handler fires command '%ls'", buffer.c_str() );
/*
Event handlers are not part of the main flow of code, so
they are marked as non-interactive
*/
proc_push_interactive(0);
prev_status = proc_get_last_status();
parser_t &parser = parser_t::principal_parser();
block_t *block = new event_block_t(event);
parser.push_block(block);
parser.eval( buffer, io_chain_t(), TOP );
parser.pop_block();
proc_pop_interactive();
proc_set_last_status( prev_status );
}
/*
Free killed events
*/
event_free_kills();
}
/**
Handle all pending signal events
*/
static void event_fire_delayed()
{
size_t i;
/*
If is_event is one, we are running the event-handler non-recursively.
When the event handler has called a piece of code that triggers
another event, we do not want to fire delayed events because of
concurrency problems.
*/
if( ! blocked.empty() && is_event==1)
{
event_list_t new_blocked;
for( i=0; i<blocked.size(); i++ )
{
event_t *e = blocked.at(i);
if( event_is_blocked( e ) )
{
new_blocked.push_back(e);
}
else
{
event_fire_internal( e );
event_free( e );
}
}
blocked.swap(new_blocked);
}
while( sig_list[active_list].count > 0 )
{
signal_list_t *lst;
/*
Switch signal lists
*/
sig_list[1-active_list].count=0;
sig_list[1-active_list].overflow=0;
active_list=1-active_list;
/*
Set up
*/
event_t e = event_t::signal_event(0);
e.arguments.reset(new wcstring_list_t(1)); //one element
lst = &sig_list[1-active_list];
if( lst->overflow )
{
debug( 0, _( L"Signal list overflow. Signals have been ignored." ) );
}
/*
Send all signals in our private list
*/
for( int i=0; i < lst->count; i++ )
{
e.param1.signal = lst->signal[i];
e.arguments->at(0) = sig2wcs( e.param1.signal );
if( event_is_blocked( &e ) )
{
blocked.push_back(event_copy(&e, 1));
}
else
{
event_fire_internal( &e );
}
}
e.arguments.reset(NULL);
}
}
void event_fire_signal(int signal)
{
/*
This means we are in a signal handler. We must be very
careful not do do anything that could cause a memory
allocation or something else that might be bad when in a
signal handler.
*/
if( sig_list[active_list].count < SIG_UNHANDLED_MAX )
sig_list[active_list].signal[sig_list[active_list].count++]=signal;
else
sig_list[active_list].overflow=1;
}
void event_fire( event_t *event )
{
if( event && (event->type == EVENT_SIGNAL) )
{
event_fire_signal(event->param1.signal);
}
else
{
is_event++;
/*
Fire events triggered by signals
*/
event_fire_delayed();
if( event )
{
if( event_is_blocked( event ) )
{
blocked.push_back(event_copy(event, 1));
}
else
{
event_fire_internal( event );
}
}
is_event--;
}
}
void event_init()
{
}
void event_destroy()
{
for_each(events.begin(), events.end(), event_free);
events.clear();
for_each(killme.begin(), killme.end(), event_free);
killme.clear();
}
void event_free( event_t *e )
{
CHECK( e, );
delete e;
}
void event_fire_generic_internal(const wchar_t *name, ...)
{
va_list va;
wchar_t *arg;
CHECK( name, );
event_t ev(EVENT_GENERIC);
ev.str_param1 = name;
ev.arguments.reset(new wcstring_list_t);
va_start( va, name );
while( (arg=va_arg(va, wchar_t *) )!= 0 )
{
ev.arguments->push_back(arg);
}
va_end( va );
event_fire( &ev );
ev.arguments.reset(NULL);
}
event_t event_t::signal_event(int sig) {
event_t event(EVENT_SIGNAL);
event.param1.signal = sig;
return event;
}
event_t event_t::variable_event(const wcstring &str) {
event_t event(EVENT_VARIABLE);
event.str_param1 = str;
return event;
}
event_t event_t::generic_event(const wcstring &str) {
event_t event(EVENT_GENERIC);
event.str_param1 = str;
return event;
}
event_t::event_t(const event_t &x) :
type(x.type),
param1(x.param1),
str_param1(x.str_param1),
function_name(x.function_name)
{
const wcstring_list_t *ptr = x.arguments.get();
if (ptr)
arguments.reset(new wcstring_list_t(*ptr));
}

Some files were not shown because too many files have changed in this diff Show More