mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
add -O and -G to test command
they are available on Linux and OS X, and now ported to fish
This commit is contained in:
parent
9f46881c16
commit
1d67d8ff23
2 changed files with 24 additions and 12 deletions
|
@ -33,13 +33,15 @@ enum token_t
|
|||
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_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 check effective group id
|
||||
test_filetype_g, // "-g", for set-group-id
|
||||
test_filetype_h, // "-h", for symbolic links
|
||||
test_filetype_L, // "-L", same as -h
|
||||
test_filetype_O, // "-O", for check effective user id
|
||||
test_filetype_p, // "-p", for FIFO
|
||||
test_filetype_S, // "-S", socket
|
||||
|
||||
|
@ -95,9 +97,11 @@ static const struct token_info_t
|
|||
{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_g, L"-g", UNARY_PRIMARY},
|
||||
{test_filetype_h, L"-h", UNARY_PRIMARY},
|
||||
{test_filetype_L, L"-L", UNARY_PRIMARY},
|
||||
{test_filetype_O, L"-O", UNARY_PRIMARY},
|
||||
{test_filetype_p, L"-p", UNARY_PRIMARY},
|
||||
{test_filetype_S, L"-S", UNARY_PRIMARY},
|
||||
{test_filesize_s, L"-s", UNARY_PRIMARY},
|
||||
|
@ -812,25 +816,31 @@ static bool unary_primary_evaluate(test_expressions::token_t token, const wcstri
|
|||
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
|
||||
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
|
||||
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
|
||||
case test_filetype_e: // "-e", for files that exist
|
||||
return !wstat(arg, &buf);
|
||||
|
||||
case test_filetype_f: // "-f" for for regular files
|
||||
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
|
||||
case test_filetype_G: // "-G", for check effective group id
|
||||
return !lwstat(arg, &buf) && getegid() == buf.st_gid;
|
||||
|
||||
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_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_O: // "-O", for check effective user id
|
||||
return !lwstat(arg, &buf) && geteuid() == buf.st_uid;
|
||||
|
||||
case test_filetype_p: // "-p", for FIFO
|
||||
return !wstat(arg, &buf) && S_ISFIFO(buf.st_mode);
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@ The following operators are available to examine files and directories:
|
|||
- <tt>-e FILE</tt> returns true if \c FILE exists.
|
||||
- <tt>-f FILE</tt> returns true if \c FILE is a regular file.
|
||||
- <tt>-g FILE</tt> returns true if \c FILE has the set-group-ID bit set.
|
||||
- <tt>-G FILE</tt> returns true if \c FILE exists and its group matches the effective group id of this process.
|
||||
- <tt>-L FILE</tt> returns true if \c FILE is a symbolic link.
|
||||
- <tt>-O FILE</tt> returns true if \c FILE exists and its owner matches the effective user id of this process.
|
||||
- <tt>-p FILE</tt> returns true if \c FILE is a named pipe.
|
||||
- <tt>-r FILE</tt> returns true if \c FILE is marked as readable.
|
||||
- <tt>-s FILE</tt> returns true if the size of \c FILE is greater than zero.
|
||||
|
|
Loading…
Reference in a new issue