Reformat all files

This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
This commit is contained in:
Fabian Homborg 2019-05-05 12:09:25 +02:00
parent 90d64194c5
commit c2970f9618
137 changed files with 2885 additions and 2350 deletions

View File

@ -1,6 +1,6 @@
function __fish_anypython
# Try python3 first, because that's usually faster and generally nicer.
for py in python3 python2 python
for py in python3 python2 python
command -sq $py
and echo $py
and return 0

View File

@ -2,15 +2,15 @@
# by clang.fish and clang++.fish.
# We dynamically query the head at `(commandline -o)[1]` to get the correct completions.
function __fish_clang_complete
# If the result is for a value, clang only prints the value, so completions
# for `-std=` print `c++11` and not `-std=c++11` like we need. See #4174.
set -l prefix (commandline -ct | string replace -fr -- '^(.*=)[^=]*' '$1')
# If the result is for a value, clang only prints the value, so completions
# for `-std=` print `c++11` and not `-std=c++11` like we need. See #4174.
set -l prefix (commandline -ct | string replace -fr -- '^(.*=)[^=]*' '$1')
# Don't hard-code the name of the clang binary
set -l clang (commandline -o)[1]
# first get the completions from clang, with the prefix separated from the value by a comma
$clang --autocomplete=(commandline -ct | string replace -- "$prefix" "$prefix,") 2>/dev/null |
# and put it in a format that fish understands
string replace -r -- '^([^ ]+)\s*(.*)' "$prefix\$1\t\$2"
# Don't hard-code the name of the clang binary
set -l clang (commandline -o)[1]
# first get the completions from clang, with the prefix separated from the value by a comma
$clang --autocomplete=(commandline -ct | string replace -- "$prefix" "$prefix,") 2>/dev/null |
# and put it in a format that fish understands
string replace -r -- '^([^ ]+)\s*(.*)' "$prefix\$1\t\$2"
end

View File

@ -19,7 +19,7 @@ function __fish_complete_man
set -l exclude_fish_commands
# Only include fish commands when section is empty or 1
if test -z "$section" -o "$section" = "1"
set -e exclude_fish_commands
set -e exclude_fish_commands
end
set section $section"[^)]*"
@ -71,8 +71,8 @@ function __fish_complete_man
# Fish commands are not given by apropos
if not set -ql exclude_fish_commands
set -l files $__fish_data_dir/man/man1/*.1
string replace -r '.*/([^/]+)\.1$' '$1\t1: fish command' -- $files
set -l files $__fish_data_dir/man/man1/*.1
string replace -r '.*/([^/]+)\.1$' '$1\t1: fish command' -- $files
end
else
return 1

View File

@ -94,7 +94,7 @@ function __fish_complete_suffix -d "Complete using files"
if set -q files[1]
if string match -qr -- . "$desc"
set desc "\t$desc"
set desc "\t$desc"
end
if string match -qr -- . "$prefix"
# Ideally, only replace in the beginning of the string, but we have no

View File

@ -1,5 +1,5 @@
function __fish_complete_zfs_mountpoint_properties -d "Completes with ZFS mountpoint properties"
set -l OS ""
set -l OS ""
switch (uname)
case Linux
set OS "Linux"
@ -9,21 +9,21 @@ function __fish_complete_zfs_mountpoint_properties -d "Completes with ZFS mountp
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
# Others?
case "*"
set OS "unknown"
end
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
if test $OS = "SunOS"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "Linux"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
end
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
if test $OS = "SunOS"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "Linux"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
end
end

View File

@ -1,3 +1,3 @@
function __fish_complete_zfs_pools -d "Completes with available ZFS pools"
zpool list -o name,comment -H | string replace -a \t'-' ''
zpool list -o name,comment -H | string replace -a \t'-' ''
end

View File

@ -1,44 +1,44 @@
function __fish_complete_zfs_ro_properties -d "Completes with ZFS read-only properties"
echo -e "available\t"(_ "Available space")
echo -e "avail\t"(_ "Available space")
echo -e "compressratio\t"(_ "Achieved compression ratio")
echo -e "creation\t"(_ "Dataset creation time")
echo -e "clones\t"(_ "Snapshot clones")
echo -e "defer_destroy\t"(_ "Marked for deferred destruction")
echo -e "filesystem_count\t"(_ "Total lower-level filesystems and volumes")
echo -e "logicalreferenced\t"(_ "Logical total space")
echo -e "lrefer\t"(_ "Logical total space")
echo -e "logicalused\t"(_ "Logical used space")
echo -e "lused\t"(_ "Logical used space")
echo -e "mounted\t"(_ "Is currently mounted?")
echo -e "origin\t"(_ "Source snapshot")
if __fish_is_zfs_feature_enabled "feature@extensible_dataset"
echo -e "receive_resume_token\t"(_ "Token for interrupted reception resumption")
end
echo -e "referenced\t"(_ "Total space")
echo -e "refer\t"(_ "Total space")
echo -e "refcompressratio\t"(_ "Achieved compression ratio of referenced space")
echo -e "snapshot_count\t"(_ "Total lower-level snapshots")
echo -e "type\t"(_ "Dataset type")
echo -e "used\t"(_ "Space used by dataset and children")
echo -e "usedbychildren\t"(_ "Space used by children datasets")
echo -e "usedbydataset\t"(_ "Space used by dataset itself")
echo -e "usedbyrefreservation\t"(_ "Space used by refreservation")
echo -e "usedbysnapshots\t"(_ "Space used by dataset snapshots")
echo -e "userrefs\t"(_ "Holds count")
echo -e "volblocksize\t"(_ "Volume block size")
echo -e "written\t"(_ "Referenced data written since previous snapshot")
# Autogenerate userused@$USER list; only usernames are supported by the completion, but the zfs command supports more formats
echo -e "available\t"(_ "Available space")
echo -e "avail\t"(_ "Available space")
echo -e "compressratio\t"(_ "Achieved compression ratio")
echo -e "creation\t"(_ "Dataset creation time")
echo -e "clones\t"(_ "Snapshot clones")
echo -e "defer_destroy\t"(_ "Marked for deferred destruction")
echo -e "filesystem_count\t"(_ "Total lower-level filesystems and volumes")
echo -e "logicalreferenced\t"(_ "Logical total space")
echo -e "lrefer\t"(_ "Logical total space")
echo -e "logicalused\t"(_ "Logical used space")
echo -e "lused\t"(_ "Logical used space")
echo -e "mounted\t"(_ "Is currently mounted?")
echo -e "origin\t"(_ "Source snapshot")
if __fish_is_zfs_feature_enabled "feature@extensible_dataset"
echo -e "receive_resume_token\t"(_ "Token for interrupted reception resumption")
end
echo -e "referenced\t"(_ "Total space")
echo -e "refer\t"(_ "Total space")
echo -e "refcompressratio\t"(_ "Achieved compression ratio of referenced space")
echo -e "snapshot_count\t"(_ "Total lower-level snapshots")
echo -e "type\t"(_ "Dataset type")
echo -e "used\t"(_ "Space used by dataset and children")
echo -e "usedbychildren\t"(_ "Space used by children datasets")
echo -e "usedbydataset\t"(_ "Space used by dataset itself")
echo -e "usedbyrefreservation\t"(_ "Space used by refreservation")
echo -e "usedbysnapshots\t"(_ "Space used by dataset snapshots")
echo -e "userrefs\t"(_ "Holds count")
echo -e "volblocksize\t"(_ "Volume block size")
echo -e "written\t"(_ "Referenced data written since previous snapshot")
# Autogenerate userused@$USER list; only usernames are supported by the completion, but the zfs command supports more formats
for user in (__fish_print_users)
set -l tabAndBefore (echo -e "userused@$user\t")
printf (_ "%sDataset space use by user %s\n") $tabAndBefore $user
end
# Autogenerate groupused@$USER list
# Autogenerate groupused@$USER list
for group in (__fish_print_groups)
set -l tabAndBefore (echo -e "groupused@$group\t")
printf (_ "%sDataset space use by group %s\n") $tabAndBefore $group
end
# Autogenerate written@$SNAPSHOT list
# Autogenerate written@$SNAPSHOT list
for snapshot in (__fish_print_zfs_snapshots)
set -l tabAndBefore (echo -e "written@$snapshot\t")
printf (_ "%sReferenced data written since snapshot %s\n") $tabAndBefore $snapshot

View File

@ -1,5 +1,5 @@
function __fish_complete_zfs_rw_properties -d "Completes with ZFS read-write properties"
set -l OS ""
set -l OS ""
switch (uname)
case Linux
set OS "Linux"
@ -9,89 +9,89 @@ function __fish_complete_zfs_rw_properties -d "Completes with ZFS read-write pro
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
# Others?
case "*"
set OS "unknown"
end
echo -e "aclinherit\t"(_ "Inheritance of ACL entries")" (discard, noallow, restricted, passthrough, passthrough-x)"
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "canmount\t"(_ "Is the dataset mountable")" (on, off, noauto)"
set -l additional_algs ''
if contains -- $OS FreeBSD SunOS
set additional_algs "$additional_algs, noparity"
end
if __fish_is_zfs_feature_enabled "feature@sha512"
set additional_algs "$additional_algs, sha512"
end
if __fish_is_zfs_feature_enabled "feature@skein"
set additional_algs "$additional_algs, skein"
end
if __fish_is_zfs_feature_enabled "feature@edonr"
set additional_algs "$additional_algs, edonr"
end
echo -e "checksum\t"(_ "Data checksum")" (on, off, fletcher2, fletcher4, sha256$additional_algs)"
if __fish_is_zfs_feature_enabled "feature@lz4_compress"
set additional_algs ", lz4"
end
echo -e "compression\t"(_ "Compression algorithm")" (on, off, lzjb$additional_algs, gzip, gzip-[1-9], zle)"
set -e additional_algs
echo -e "copies\t"(_ "Number of copies of data")" (1, 2, 3)"
echo -e "dedup\t"(_ "Deduplication")" (on, off, verify, sha256[,verify])"
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "filesystem_limit\t"(_ "Max number of filesystems and volumes")" (COUNT, none)"
echo -e "mountpoint\t"(_ "Mountpoint")" (PATH, none, legacy)"
echo -e "primarycache\t"(_ "Which data to cache in ARC")" (all, none, metadata)"
echo -e "quota\t"(_ "Max size of dataset and children")" (SIZE, none)"
echo -e "snapshot_limit\t"(_ "Max number of snapshots")" (COUNT, none)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "recordsize\t"(_ "Suggest block size")" (SIZE)"
echo -e "redundant_metadata\t"(_ "How redundant are the metadata")" (all, most)"
echo -e "refquota\t"(_ "Max space used by dataset itself")" (SIZE, none)"
echo -e "refreservation\t"(_ "Min space guaranteed to dataset itself")" (SIZE, none)"
echo -e "reservation\t"(_ "Min space guaranteed to dataset")" (SIZE, none)"
echo -e "secondarycache\t"(_ "Which data to cache in L2ARC")" (all, none, metadata)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
echo -e "sharenfs\t"(_ "Share in NFS")" (on, off, OPTS)"
echo -e "logbias\t"(_ "Hint for handling of synchronous requests")" (latency, throughput)"
echo -e "snapdir\t"(_ "Hide .zfs directory")" (hidden, visible)"
echo -e "sync\t"(_ "Handle of synchronous requests")" (standard, always, disabled)"
echo -e "volsize\t"(_ "Volume logical size")" (SIZE)"
echo -e "aclinherit\t"(_ "Inheritance of ACL entries")" (discard, noallow, restricted, passthrough, passthrough-x)"
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "canmount\t"(_ "Is the dataset mountable")" (on, off, noauto)"
set -l additional_algs ''
if contains -- $OS FreeBSD SunOS
set additional_algs "$additional_algs, noparity"
end
if __fish_is_zfs_feature_enabled "feature@sha512"
set additional_algs "$additional_algs, sha512"
end
if __fish_is_zfs_feature_enabled "feature@skein"
set additional_algs "$additional_algs, skein"
end
if __fish_is_zfs_feature_enabled "feature@edonr"
set additional_algs "$additional_algs, edonr"
end
echo -e "checksum\t"(_ "Data checksum")" (on, off, fletcher2, fletcher4, sha256$additional_algs)"
if __fish_is_zfs_feature_enabled "feature@lz4_compress"
set additional_algs ", lz4"
end
echo -e "compression\t"(_ "Compression algorithm")" (on, off, lzjb$additional_algs, gzip, gzip-[1-9], zle)"
set -e additional_algs
echo -e "copies\t"(_ "Number of copies of data")" (1, 2, 3)"
echo -e "dedup\t"(_ "Deduplication")" (on, off, verify, sha256[,verify])"
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "filesystem_limit\t"(_ "Max number of filesystems and volumes")" (COUNT, none)"
echo -e "mountpoint\t"(_ "Mountpoint")" (PATH, none, legacy)"
echo -e "primarycache\t"(_ "Which data to cache in ARC")" (all, none, metadata)"
echo -e "quota\t"(_ "Max size of dataset and children")" (SIZE, none)"
echo -e "snapshot_limit\t"(_ "Max number of snapshots")" (COUNT, none)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "recordsize\t"(_ "Suggest block size")" (SIZE)"
echo -e "redundant_metadata\t"(_ "How redundant are the metadata")" (all, most)"
echo -e "refquota\t"(_ "Max space used by dataset itself")" (SIZE, none)"
echo -e "refreservation\t"(_ "Min space guaranteed to dataset itself")" (SIZE, none)"
echo -e "reservation\t"(_ "Min space guaranteed to dataset")" (SIZE, none)"
echo -e "secondarycache\t"(_ "Which data to cache in L2ARC")" (all, none, metadata)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
echo -e "sharenfs\t"(_ "Share in NFS")" (on, off, OPTS)"
echo -e "logbias\t"(_ "Hint for handling of synchronous requests")" (latency, throughput)"
echo -e "snapdir\t"(_ "Hide .zfs directory")" (hidden, visible)"
echo -e "sync\t"(_ "Handle of synchronous requests")" (standard, always, disabled)"
echo -e "volsize\t"(_ "Volume logical size")" (SIZE)"
# Autogenerate userquota@$USER list; only usernames are supported by the completion, but the zfs command supports more formats
# Autogenerate userquota@$USER list; only usernames are supported by the completion, but the zfs command supports more formats
for user in (__fish_print_users)
set -l tabAndBefore (echo -e "userquota@$user\t")
printf (_ "%sMax usage by user %s\n") $tabAndBefore $user
end
# Autogenerate groupquota@$USER list
# Autogenerate groupquota@$USER list
for group in (__fish_print_groups)
set -l tabAndBefore (echo -e "groupquota@$group\t")
printf (_ "%sMax usage by group %s\n") $tabAndBefore $group
end
if test $OS = "SunOS"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "mlslabel\t"(_ "Can the dataset be mounted in a zone with Trusted Extensions enabled")" (LABEL, none)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
echo -e "zoned\t"(_ "Managed from a non-global zone")" (on, off)"
else if test $OS = "Linux"
echo -e "acltype\t"(_ "Use no ACL or POSIX ACL")" (noacl, posixacl)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "snapdev\t"(_ "Hide volume snapshots")" (hidden, visible)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "FreeBSD"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "volmode\t"(_ "How to expose volumes to OS")" (default, geom, dev, none)"
end
# User properties; the /dev/null redirection masks the possible "no datasets available"
zfs list -o all 2>/dev/null | head -n 1 | string replace -a -r "\s+" "\n" | string match -e ":" | string lower
if test $OS = "SunOS"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "mlslabel\t"(_ "Can the dataset be mounted in a zone with Trusted Extensions enabled")" (LABEL, none)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
echo -e "zoned\t"(_ "Managed from a non-global zone")" (on, off)"
else if test $OS = "Linux"
echo -e "acltype\t"(_ "Use no ACL or POSIX ACL")" (noacl, posixacl)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "snapdev\t"(_ "Hide volume snapshots")" (hidden, visible)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "FreeBSD"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "volmode\t"(_ "How to expose volumes to OS")" (default, geom, dev, none)"
end
# User properties; the /dev/null redirection masks the possible "no datasets available"
zfs list -o all 2>/dev/null | head -n 1 | string replace -a -r "\s+" "\n" | string match -e ":" | string lower
end

View File

@ -1,5 +1,5 @@
function __fish_complete_zfs_write_once_properties -d "Completes with ZFS properties which can only be written at filesystem creation, and only be read thereafter"
set -l OS ""
set -l OS ""
switch (uname)
case Linux
set OS "Linux"
@ -9,22 +9,22 @@ function __fish_complete_zfs_write_once_properties -d "Completes with ZFS proper
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
# Others?
case "*"
set OS "unknown"
end
echo -e "normalization\t"(_ "Unicode normalization")" (none, formC, formD, formKC, formKD)"
echo -e "utf8only\t"(_ "Reject non-UTF-8-compliant filenames")" (on, off)"
if test $OS = "Linux"
echo -e "overlay\t"(_ "Allow overlay mount")" (on, off)"
if command -sq sestatus # SELinux is enabled
echo -e "context\t"(_ "SELinux context for the child filesystem")
echo -e "fscontext\t"(_ "SELinux context for the filesystem being mounted")
echo -e "defcontext\t"(_ "SELinux context for unlabeled files")
echo -e "rootcontext\t"(_ "SELinux context for the root inode of the filesystem")
end
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive)"
else
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive, mixed)"
end
echo -e "normalization\t"(_ "Unicode normalization")" (none, formC, formD, formKC, formKD)"
echo -e "utf8only\t"(_ "Reject non-UTF-8-compliant filenames")" (on, off)"
if test $OS = "Linux"
echo -e "overlay\t"(_ "Allow overlay mount")" (on, off)"
if command -sq sestatus # SELinux is enabled
echo -e "context\t"(_ "SELinux context for the child filesystem")
echo -e "fscontext\t"(_ "SELinux context for the filesystem being mounted")
echo -e "defcontext\t"(_ "SELinux context for unlabeled files")
echo -e "rootcontext\t"(_ "SELinux context for the root inode of the filesystem")
end
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive)"
else
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive, mixed)"
end
end

View File

@ -8,7 +8,8 @@ function __fish_describe_command -d "Command used to find descriptions for comma
# TODO: stop interpolating argv into regex, and remove this hack.
string match --quiet --regex '^[a-zA-Z0-9_ ]+$' -- "$argv"
or return
type -q apropos; or return
type -q apropos
or return
apropos $argv 2>/dev/null | awk -v FS=" +- +" '{
split($1, names, ", ");
for (name in names)

View File

@ -1,9 +1,9 @@
# Retrieves the first non-switch argument from the command line buffer
function __fish_first_token
set -l tokens (commandline -co)
set -e tokens[1]
set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens)
if set -q tokens[1]
echo $tokens[1]
end
set -l tokens (commandline -co)
set -e tokens[1]
set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens)
if set -q tokens[1]
echo $tokens[1]
end
end

View File

@ -1,5 +1,5 @@
# determine if this is the very first argument (regardless if switch or not)
function __fish_is_first_arg
set -l tokens (commandline -co)
test (count $tokens) -eq 1
set -l tokens (commandline -co)
test (count $tokens) -eq 1
end

View File

@ -1,4 +1,4 @@
# Whether or not the current token is a switch
function __fish_is_switch
string match -qr -- '^-' ""(commandline -ct)
string match -qr -- '^-' ""(commandline -ct)
end

View File

@ -1,25 +1,25 @@
# Generates a list of parent directories for a given path
# i.e. /a/b/c/d -> [/a/b/c/, /a/b/, /a/, and /a]
function __fish_parent_directories
if test (count $argv) -ne 1
# for use in completions, so don't spew error messages
return 1
end
if test (count $argv) -ne 1
# for use in completions, so don't spew error messages
return 1
end
set -l splits (string split '/' $argv[1])
set -l parents
set -l splits (string split '/' $argv[1])
set -l parents
for split in $splits
if test (string length "$split") -eq 0
continue
end
for split in $splits
if test (string length "$split") -eq 0
continue
end
set parents "$parents[1]/$split" $parents
end
set parents "$parents[1]/$split" $parents
end
for parent in $parents
echo $parent
end
for parent in $parents
echo $parent
end
return 0
return 0
end

View File

@ -1,14 +1,14 @@
function __fish_parse_configure
if test (count $argv) -ne 1
echo "Usage: parse_configure path/to/configure" 1>&2
return 1
end
if test (count $argv) -ne 1
echo "Usage: parse_configure path/to/configure" 1>&2
return 1
end
# `complete` parses `./configure` as `configure` so we have to handle all paths, not just ./
if not test -x $argv[1]
printf "Cannot find or execute '%s'\n" $argv[1] 1>&2
return 1
end
# `complete` parses `./configure` as `configure` so we have to handle all paths, not just ./
if not test -x $argv[1]
printf "Cannot find or execute '%s'\n" $argv[1] 1>&2
return 1
end
# Must support output along the lines of
# -h, --help display this help and exit
@ -17,56 +17,56 @@ function __fish_parse_configure
# -V, --version display version information and exit
# -q, --quiet, --silent do not print `checking ...' messages
set -l next_line
set -l line
set -l buffer
# Just fish's `./configure --help` takes ~350ms to run, before parsing
# The following chain attempts to extract the help message:
cat $argv[1] | tr \n \u0e | sed -n 's/.*Report the --help message\(.*\?\)ac_status.*/\1/; s/ac_status.*//p' | tr \u0e \n |
while test "$next_line" != "" || read -lL next_line
# In autoconfigure scripts, the first column wraps at 26 chars
# echo next_line: $next_line
# echo old_line: $line
if test "$line" = ""
set line $next_line
set next_line "" # mark it as consumed
continue
else if string match -qr '^( |\t){2,}[^-]\S*' -- $next_line
# echo "continuation line found. Old value of line: " \"$line\"
set line "$line "(string trim $next_line)
set next_line "" # mark it as consumed
continue
end
set -l next_line
set -l line
set -l buffer
# Just fish's `./configure --help` takes ~350ms to run, before parsing
# The following chain attempts to extract the help message:
cat $argv[1] | tr \n \u0e | sed -n 's/.*Report the --help message\(.*\?\)ac_status.*/\1/; s/ac_status.*//p' | tr \u0e \n |
while test "$next_line" != "" || read -lL next_line
# In autoconfigure scripts, the first column wraps at 26 chars
# echo next_line: $next_line
# echo old_line: $line
if test "$line" = ""
set line $next_line
set next_line "" # mark it as consumed
continue
else if string match -qr '^( |\t){2,}[^-]\S*' -- $next_line
# echo "continuation line found. Old value of line: " \"$line\"
set line "$line "(string trim $next_line)
set next_line "" # mark it as consumed
continue
end
# echo line: $line
# echo line: $line
# Search for one or more strings starting with `-` separated by commas
if string replace -fr '^\s+(-.*?)\s+([^\s\-].*)' '$1\n$2' -- $line | read -lL opts description
for opt in (string split -n , -- $opts | string trim)
# Search for one or more strings starting with `-` separated by commas
if string replace -fr '^\s+(-.*?)\s+([^\s\-].*)' '$1\n$2' -- $line | read -lL opts description
for opt in (string split -n , -- $opts | string trim)
if string match -qr -- '--[a-z_0-9-]+=\[.*\]' $opt
# --option=[OPTIONAL_VALUE]
string replace -r -- '(--[a-z_0-9-]+)=.*' '$1' $opt | read opt
else if string match -qr -- '--[a-z_0-9-]+\[=.*\]' $opt
# --option[=OPTIONAL_VALUE]
string replace -r -- '(--[a-z_0-9-]+)\[=.*' '$1' $opt | read opt
else if string match -qr -- '--[a-z_0-9-]+=[A-Z]+' $opt
# --option=CLASS_OF_VALUE (eg FILE or DIR)
string replace -r -- '(--[a-z_0-9-]+)=.*' '$1' $opt | read opt
else if string match -qr -- '--[a-z_0-9-]+=\S+' $opt
# --option=literal_value, leave as-is
else if string match -qr -- '--[a-z_0-9-]+$' $opt
# long option, leave as-is
else if string match -qr -- '-[^-]$' $opt
# short option, leave as-is
else
continue
end
if string match -qr -- '--[a-z_0-9-]+=\[.*\]' $opt
# --option=[OPTIONAL_VALUE]
string replace -r -- '(--[a-z_0-9-]+)=.*' '$1' $opt | read opt
else if string match -qr -- '--[a-z_0-9-]+\[=.*\]' $opt
# --option[=OPTIONAL_VALUE]
string replace -r -- '(--[a-z_0-9-]+)\[=.*' '$1' $opt | read opt
else if string match -qr -- '--[a-z_0-9-]+=[A-Z]+' $opt
# --option=CLASS_OF_VALUE (eg FILE or DIR)
string replace -r -- '(--[a-z_0-9-]+)=.*' '$1' $opt | read opt
else if string match -qr -- '--[a-z_0-9-]+=\S+' $opt
# --option=literal_value, leave as-is
else if string match -qr -- '--[a-z_0-9-]+$' $opt
# long option, leave as-is
else if string match -qr -- '-[^-]$' $opt
# short option, leave as-is
else
continue
end
echo "$opt"\t"$description" # parsed by `complete` as value and description
end
end
echo "$opt"\t"$description" # parsed by `complete` as value and description
end
end
set line ""
end
set line ""
end
end

View File

@ -1,5 +1,5 @@
function __fish_pipestatus_with_signal --description "Print arguments from \$pipestatus replacing values with signal names where appropriate"
for pstat in $argv
__fish_status_to_signal $pstat
__fish_status_to_signal $pstat
end
end

View File

@ -1,3 +1,3 @@
function __fish_portage_print_available_pkgs --description 'Print all available packages'
find (__fish_portage_print_repository_paths) -mindepth 2 -maxdepth 2 -type d ! '(' '(' -path '*/eclass/*' -o -path '*/metadata/*' -o -path '*/profiles/*' -o -path '*/.*/*' ')' -prune ')' -printf '%P\n'
find (__fish_portage_print_repository_paths) -mindepth 2 -maxdepth 2 -type d ! '(' '(' -path '*/eclass/*' -o -path '*/metadata/*' -o -path '*/profiles/*' -o -path '*/.*/*' ')' -prune ')' -printf '%P\n'
end

View File

@ -1,3 +1,3 @@
function __fish_portage_print_installed_pkgs --description 'Print all installed packages (non-deduplicated)'
find /var/db/pkg -mindepth 2 -maxdepth 2 -type d -printf '%P\n' | string replace -r -- '-[0-9][0-9.]*.*$' ''
find /var/db/pkg -mindepth 2 -maxdepth 2 -type d -printf '%P\n' | string replace -r -- '-[0-9][0-9.]*.*$' ''
end

View File

@ -1,4 +1,4 @@
function __fish_portage_print_repository_names --description 'Print the names of all configured repositories'
# repos.conf may be a file or a directory
find /etc/portage/repos.conf -type f -exec cat '{}' + | string replace -r --filter '^\s*\[([[:alnum:]_][[:alnum:]_-]*)\]' '$1' | string match -v -e DEFAULT
# repos.conf may be a file or a directory
find /etc/portage/repos.conf -type f -exec cat '{}' + | string replace -r --filter '^\s*\[([[:alnum:]_][[:alnum:]_-]*)\]' '$1' | string match -v -e DEFAULT
end

View File

@ -1,4 +1,4 @@
function __fish_portage_print_repository_paths --description 'Print the paths of all configured repositories'
# repos.conf may be a file or a directory
find /etc/portage/repos.conf -type f -exec cat '{}' + | string replace -r --filter '^\s*location\s*=\s*(\S+)' '$1'
# repos.conf may be a file or a directory
find /etc/portage/repos.conf -type f -exec cat '{}' + | string replace -r --filter '^\s*location\s*=\s*(\S+)' '$1'
end

View File

@ -1,16 +1,16 @@
# returns 0 only if previous argument is one of the supplied arguments
function __fish_prev_arg_in
set -l tokens (commandline -co)
set -l tokenCount (count $tokens)
if test $tokenCount -lt 2
# need at least cmd and prev argument
return 1
end
for arg in $argv
if string match -q -- $tokens[-1] $arg
return 0
end
end
set -l tokens (commandline -co)
set -l tokenCount (count $tokens)
if test $tokenCount -lt 2
# need at least cmd and prev argument
return 1
end
for arg in $argv
if string match -q -- $tokens[-1] $arg
return 0
end
end
return 1
return 1
end

View File

@ -73,18 +73,23 @@ function __fish_print_help --description "Print help message for the specified f
# Remove man's bolding
set -l name (string replace -ra '(.)'\b'.' '$1' -- $line)
# We start after we have the name
contains -- $name NAME; and set have_name 1; and continue
contains -- $name NAME
and set have_name 1
and continue
# We ignore the SYNOPSIS header
contains -- $name SYNOPSIS; and continue
contains -- $name SYNOPSIS
and continue
# Everything after COPYRIGHT is useless
contains -- $name COPYRIGHT; and break
contains -- $name COPYRIGHT
and break
# not leading space, and not empty, so must contain a non-space
# in the first column. That makes it a header/footer.
set line_type meta
end
set -q have_name[1]; or continue
set -q have_name[1]
or continue
switch $state
case normal
switch $line_type

View File

@ -100,10 +100,10 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
set known_hosts $known_hosts (string replace -rfi '.*KnownHostsFile\s*' '' <$file)
end
end
for file in $known_hosts
for file in $known_hosts
if test -r $file
# Ignore hosts that are hashed, commented or @-marked and strip the key.
awk '$1 !~ /[|#@]/ {
# Ignore hosts that are hashed, commented or @-marked and strip the key.
awk '$1 !~ /[|#@]/ {
n=split($1, entries, ",")
for (i=1; i<=n; i++) {
# Ignore negated/wildcarded hosts.

View File

@ -1,7 +1,8 @@
# Use --installed to limit to installed packages only
function __fish_print_packages
argparse --name=__fish_print_packages 'i/installed' -- $argv
or return;
or return
set -l only_installed 1
if not set -q _flag_installed

View File

@ -11,7 +11,7 @@ function __fish_print_pipestatus --description "Print pipestatus for prompt"
set -l sep (set_color normal){$brace_sep_color}{$separator}(set_color normal){$status_color}
set -l last_pipestatus_string (string join "$sep" (__fish_pipestatus_with_signal $argv))
printf "%s%s%s%s%s%s%s%s%s%s" (set_color normal )$brace_sep_color $left_brace \
(set_color normal) $status_color $last_pipestatus_string (set_color normal) \
$brace_sep_color $right_brace (set_color normal)
(set_color normal) $status_color $last_pipestatus_string (set_color normal) \
$brace_sep_color $right_brace (set_color normal)
end
end

View File

@ -1,3 +1,3 @@
function __fish_print_xwindows --description 'Print X windows'
xwininfo -root -children | sed '/^\s\+0x/!d; /(has no name)/d; s/^\s*\(\S\+\)\s\+"\(.\+\)":\s\+(\(.*\)).*$/\1\t\2 (\3)/'
xwininfo -root -children | sed '/^\s\+0x/!d; /(has no name)/d; s/^\s*\(\S\+\)\s\+"\(.\+\)":\s\+(\(.*\)).*$/\1\t\2 (\3)/'
end

View File

@ -1,5 +1,5 @@
function __fish_print_zfs_bookmarks -d "Lists ZFS bookmarks, if the feature is enabled"
if __fish_is_zfs_feature_enabled 'feature@bookmarks'
zfs list -t bookmark -o name -H
end
if __fish_is_zfs_feature_enabled 'feature@bookmarks'
zfs list -t bookmark -o name -H
end
end

View File

@ -1,3 +1,3 @@
function __fish_print_zfs_filesystems -d "Lists ZFS filesystems"
zfs list -t filesystem -o name -H
zfs list -t filesystem -o name -H
end

View File

@ -1,3 +1,3 @@
function __fish_print_zfs_snapshots -d "Lists ZFS snapshots"
zfs list -t snapshot -o name -H
zfs list -t snapshot -o name -H
end

View File

@ -1,3 +1,3 @@
function __fish_print_zfs_volumes -d "Lists ZFS volumes"
zfs list -t volume -o name -H
zfs list -t volume -o name -H
end

View File

@ -1,22 +1,22 @@
function __fish_seen_argument
argparse 's/short=+' 'l/long=+' -- $argv
argparse 's/short=+' 'l/long=+' -- $argv
set cmd (commandline -co)
set -e cmd[1]
for t in $cmd
for s in $_flag_s
if string match -qr "^-[A-z0-9]*"$s"[A-z0-9]*\$" -- $t
return 0
end
end
set cmd (commandline -co)
set -e cmd[1]
for t in $cmd
for s in $_flag_s
if string match -qr "^-[A-z0-9]*"$s"[A-z0-9]*\$" -- $t
return 0
end
end
for l in $_flag_l
if string match -q -- "--$l" $t
return 0
end
end
end
for l in $_flag_l
if string match -q -- "--$l" $t
return 0
end
end
end
return 1
return 1
end

View File

@ -1,14 +1,14 @@
# Returns whether we *should* complete a -s or --long argument.
# The preference is NOT to do so, i.e. prefer subcommands over switches.
function __fish_should_complete_switches
for arg in (commandline -ct)[-1..1]
if not string match -qr -- "^-\S*\$" "$arg"
return 1
end
end
if string match -qr -- "^-" (commandline -ct)[-1]
return 0
end
for arg in (commandline -ct)[-1..1]
if not string match -qr -- "^-\S*\$" "$arg"
return 1
end
end
if string match -qr -- "^-" (commandline -ct)[-1]
return 0
end
return 1
return 1
end

View File

@ -1,21 +1,21 @@
# uses `whatis` if available to describe a command
function __fish_whatis
set -l cmd $argv[1]
set -l fallback
if set -q argv[2]
set fallback $argv[2]
end
set -l cmd $argv[1]
set -l fallback
if set -q argv[2]
set fallback $argv[2]
end
set -l description (whatis $cmd 2>/dev/null | string replace -r '.*? - ' '')[1]
if not string match -qr -- "." "$description"
printf '%s\n' $description
return 0
else if not string match -q -- "$fallback" ""
printf '%s\n' $fallback
return 0
else
return 1
end
set -l description (whatis $cmd 2>/dev/null | string replace -r '.*? - ' '')[1]
if not string match -qr -- "." "$description"
printf '%s\n' $description
return 0
else if not string match -q -- "$fallback" ""
printf '%s\n' $fallback
return 0
else
return 1
end
end

View File

@ -16,7 +16,7 @@ set -g fish_prompt_git_status_renamed '➜'
set -g fish_prompt_git_status_copied '⇒'
set -g fish_prompt_git_status_deleted '✖'
set -g fish_prompt_git_status_untracked '?'
set -g fish_prompt_git_status_unmerged '!'
set -g fish_prompt_git_status_unmerged !
set -g fish_prompt_git_status_order added modified renamed copied deleted untracked unmerged

View File

@ -33,23 +33,30 @@ function _fish_systemctl --description 'Call systemctl with some options from th
help reset-failed list-dependencies list-units revert add-{wants,requires} edit
case enable
# This will only work for "list-unit-files", but won't print an error for "list-units".
set -q _flag_state; or set _flag_state disabled
set -q _flag_state
or set _flag_state disabled
case disable
set -q _flag_state; or set _flag_state enabled
set -q _flag_state
or set _flag_state enabled
case start
# Running `start` on an already started unit isn't an _error_, but useless.
set -q _flag_state; or set _flag_state dead,failed
set -q _flag_state
or set _flag_state dead,failed
case mask
set -q _flag_state; or set _flag_state loaded
set -q _flag_state
or set _flag_state loaded
case unmask
set -q _flag_state; or set _flag_state masked
set -q _flag_state
or set _flag_state masked
case stop kill
# TODO: Is "kill" useful on other unit types?
# Running as the catch-all, "mounted" for .mount units, "active" for .target.
set -q _flag_state; or set _flag_state running,mounted,active
set -q _flag_state
or set _flag_state running,mounted,active
case isolate set-default
# These only take one unit.
set -q argv[1]; and return
set -q argv[1]
and return
case list-sockets
set _flag_type socket
case list-timers
@ -65,11 +72,16 @@ function _fish_systemctl --description 'Call systemctl with some options from th
end
# Add the flags back so we can pass them to our systemctl invocations.
set -q _flag_type; and set passflags $passflags --type=$_flag_type
set -q _flag_state; and set passflags $passflags --state=$_flag_state
set -q _flag_property; and set passflags $passflags --property=$_flag_property
set -q _flag_machine; and set passflags $passflags --machine=$_flag_machine
set -q _flag_host; and set passflags $passflags --host=$_flag_host
set -q _flag_type
and set passflags $passflags --type=$_flag_type
set -q _flag_state
and set passflags $passflags --state=$_flag_state
set -q _flag_property
and set passflags $passflags --property=$_flag_property
set -q _flag_machine
and set passflags $passflags --machine=$_flag_machine
set -q _flag_host
and set passflags $passflags --host=$_flag_host
# Output looks like
# systemd-tmpfiles-clean.timer [more whitespace] loaded active waiting Daily Cleanup[...]

View File

@ -53,12 +53,14 @@ function abbr --description "Manage abbreviations"
else if set -q _flag_query[1]
# "--query": Check if abbrs exist.
# If we don't have an argument, it's an automatic failure.
set -q argv[1]; or return 1
set -q argv[1]
or return 1
set -l escaped _fish_abbr_(string escape --style=var -- $argv)
# We return 0 if any arg exists, whereas `set -q` returns the number of undefined arguments.
# But we should be consistent with `type -q` and `command -q`.
for var in $escaped
set -q $escaped; and return 0
set -q $escaped
and return 0
end
return 1
else

View File

@ -1,7 +1,8 @@
function fish_clipboard_copy
# Copy the current selection, or the entire commandline if that is empty.
set -l cmdline (commandline --current-selection)
test -n "$cmdline"; or set cmdline (commandline)
test -n "$cmdline"
or set cmdline (commandline)
if type -q pbcopy
printf '%s\n' $cmdline | pbcopy
else if type -q xsel

View File

@ -3,12 +3,12 @@ function fish_config --description "Launch fish's web based configuration"
if set -l python (__fish_anypython)
$python "$__fish_data_dir/tools/web_config/webconfig.py" $argv
else
echo (set_color $fish_color_error)Cannot launch the web configuration tool:(set_color normal)
echo (set_color -o)fish_config(set_color normal) requires Python.
echo Installing python2 or python3 will fix this, and also enable completions to be
echo automatically generated from man pages.\n
echo To change your prompt, create a (set_color -o)fish_prompt(set_color normal) function.
echo There are examples in (set_color $fish_color_valid_path)$__fish_data_dir/tools/web_config/sample_prompts(set_color normal).\n
echo You can tweak your colors by setting the (set_color $fish_color_search_match)\$fish_color_\*(set_color normal) variables.
echo (set_color $fish_color_error)Cannot launch the web configuration tool:(set_color normal)
echo (set_color -o)fish_config(set_color normal) requires Python.
echo Installing python2 or python3 will fix this, and also enable completions to be
echo automatically generated from man pages.\n
echo To change your prompt, create a (set_color -o)fish_prompt(set_color normal) function.
echo There are examples in (set_color $fish_color_valid_path)$__fish_data_dir/tools/web_config/sample_prompts(set_color normal).\n
echo You can tweak your colors by setting the (set_color $fish_color_search_match)\$fish_color_\*(set_color normal) variables.
end
end

View File

@ -454,7 +454,8 @@ function fish_git_prompt --description "Prompt function for Git"
set b (string replace refs/heads/ '' -- $b)
set -q __fish_git_prompt_shorten_branch_char_suffix
or set -l __fish_git_prompt_shorten_branch_char_suffix "…"
if string match -qr '^\d+$' "$__fish_git_prompt_shorten_branch_len"; and test (string length "$b") -gt $__fish_git_prompt_shorten_branch_len
if string match -qr '^\d+$' "$__fish_git_prompt_shorten_branch_len"
and test (string length "$b") -gt $__fish_git_prompt_shorten_branch_len
set b (string sub -l "$__fish_git_prompt_shorten_branch_len" "$b")"$__fish_git_prompt_shorten_branch_char_suffix"
end
if test -n "$b"
@ -548,7 +549,8 @@ function __fish_git_prompt_informative_status
set -l untrackedfiles (command git ls-files --others --exclude-standard | count)
set -l stashstate 0
set -l stashfile "$argv[1]/logs/refs/stash"
if set -q __fish_git_prompt_showstashstate; and test -e "$stashfile"
if set -q __fish_git_prompt_showstashstate
and test -e "$stashfile"
set stashstate (count < $stashfile)
end

View File

@ -16,7 +16,7 @@ set -g fish_prompt_hg_status_modified '*'
set -g fish_prompt_hg_status_copied '⇒'
set -g fish_prompt_hg_status_deleted '✖'
set -g fish_prompt_hg_status_untracked '?'
set -g fish_prompt_hg_status_unmerged '!'
set -g fish_prompt_hg_status_unmerged !
set -g fish_prompt_hg_status_order added modified copied deleted untracked unmerged

View File

@ -59,7 +59,7 @@ function __yarn_installed_packages
if set -l python (__fish_anypython)
$python -c 'import json, sys; data = json.load(sys.stdin);
print("\n".join(data["dependencies"])); print("\n".join(data["devDependencies"]))' < $package_json 2>/dev/null
print("\n".join(data["dependencies"])); print("\n".join(data["devDependencies"]))' <$package_json 2>/dev/null
else if type -q jq
jq -r '.dependencies as $a1 | .devDependencies as $a2 | ($a1 + $a2) | to_entries[] | .key' $package_json
else

View File

@ -19,4 +19,4 @@ function fish_print_hg_root
return 1
end

View File

@ -37,7 +37,7 @@ set -g __fish_svn_prompt_char_unversioned_external_color --underline cyan
set -g __fish_svn_prompt_char_unversioned_display '?'
set -g __fish_svn_prompt_char_unversioned_color purple
set -g __fish_svn_prompt_char_missing_display '!'
set -g __fish_svn_prompt_char_missing_display !
set -g __fish_svn_prompt_char_missing_color yellow
set -g __fish_svn_prompt_char_versioned_obstructed_display '~'

View File

@ -67,9 +67,10 @@ function help --description 'Show help for the fish shell'
# If the OS appears to be Windows (graphical), try to use cygstart
if type -q cygstart
set fish_browser cygstart
# If xdg-open is available, just use that
# but only if an X session is running
else if type -q xdg-open; and set -q -x DISPLAY
# If xdg-open is available, just use that
# but only if an X session is running
else if type -q xdg-open
and set -q -x DISPLAY
set fish_browser xdg-open
end
@ -158,7 +159,7 @@ function help --description 'Show help for the fish shell'
or set -l TMPDIR /tmp
set -l tmpdir (mktemp -d $TMPDIR/help.XXXXXX)
set -l tmpname $tmpdir/help.html
echo '<meta http-equiv="refresh" content="0;URL=\''$clean_url'\'" />' > $tmpname
echo '<meta http-equiv="refresh" content="0;URL=\''$clean_url'\'" />' >$tmpname
set page_url file://$tmpname
end
end
@ -166,7 +167,7 @@ function help --description 'Show help for the fish shell'
# cmd.exe needs more coaxing.
if string match -qr 'cmd.exe$' -- $fish_browser[1]
$fish_browser /c "start $page_url"
# If browser is known to be graphical, put into background
# If browser is known to be graphical, put into background
else if contains -- $fish_browser[1] $graphical_browsers
switch $fish_browser[1]
case 'htmlview' 'x-www-browser'

View File

@ -16,7 +16,7 @@ for opt in --color=auto -G --color -F
command ls $opt $argv
end
if [ $opt = --color=auto ] &&! set -qx LS_COLORS && set -l cmd (command -s {g,}dircolors)[1]
if [ $opt = --color=auto ] && ! set -qx LS_COLORS && set -l cmd (command -s {g,}dircolors)[1]
set -l colorfile
for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
if test -f $file

View File

@ -61,7 +61,8 @@ function type --description 'Print the type of a command'
switch $func_path
case "n/a"
case "stdin"
break;
break
case "*"
echo $func_path
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -23,11 +23,11 @@ function fish_prompt --description 'Write out the prompt, prepending the Debian
echo -n -s "$USER" @ (prompt_hostname) ' ' (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) (prompt_pwd) \
(set_color normal) '# '
(set_color normal) '# '
case '*'
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $fish_color_cwd) (prompt_pwd) \
(set_color normal) '> '
(set_color normal) '> '
end
end

View File

@ -18,13 +18,13 @@ function fish_prompt --description 'Informative prompt'
printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) \
(set_color bryellow) $last_pipestatus)
printf '[%s] %s%s@%s %s%s %s%s(%s)%s \f\r> ' (date "+%H:%M:%S") (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD "$pipestatus_string" \
$status_color $last_status (set_color normal)
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD "$pipestatus_string" \
$status_color $last_status (set_color normal)
end
end

File diff suppressed because it is too large Load Diff

View File

@ -13,21 +13,25 @@ from sphinx.errors import SphinxError, SphinxWarning
# -- Helper functions --------------------------------------------------------
def strip_ext(path):
""" Remove the extension from a path. """
return os.path.splitext(path)[0]
# -- Load our Pygments lexer -------------------------------------------------
def setup(app):
from sphinx.highlighting import lexers
this_dir = os.path.dirname(os.path.realpath(__file__))
fish_indent_lexer = pygments.lexers.load_lexer_from_file(
os.path.join(this_dir, 'fish_indent_lexer.py'),
lexername='FishIndentLexer')
lexers['fish-docs-samples'] = fish_indent_lexer
os.path.join(this_dir, "fish_indent_lexer.py"), lexername="FishIndentLexer"
)
lexers["fish-docs-samples"] = fish_indent_lexer
# The default language to assume
highlight_language = 'fish-docs-samples'
highlight_language = "fish-docs-samples"
# -- Path setup --------------------------------------------------------------
@ -42,14 +46,14 @@ highlight_language = 'fish-docs-samples'
# -- Project information -----------------------------------------------------
project = 'fish-shell'
copyright = '2019, fish-shell developers'
author = 'fish-shell developers'
project = "fish-shell"
copyright = "2019, fish-shell developers"
author = "fish-shell developers"
# The short X.Y version
version = '3.1'
version = "3.1"
# The full version, including alpha/beta/rc tags
release = '3.1.0'
release = "3.1.0"
# -- General configuration ---------------------------------------------------
@ -61,20 +65,19 @@ release = '3.1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -98,7 +101,7 @@ pygments_style = None
# a list of builtin themes.
# !!! If you change this you also need to update the @import at the top
# of _static/fish-syntax-style.css
html_theme = 'nature'
html_theme = "nature"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@ -109,7 +112,7 @@ html_theme = 'nature'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
@ -119,13 +122,13 @@ html_static_path = ['_static']
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
html_sidebars = { '**': ['globaltoc.html', 'localtoc.html', 'searchbox.html'] }
html_sidebars = {"**": ["globaltoc.html", "localtoc.html", "searchbox.html"]}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'fish-shelldoc'
htmlhelp_basename = "fish-shelldoc"
# -- Options for LaTeX output ------------------------------------------------
@ -134,15 +137,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
@ -152,34 +152,36 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'fish-shell.tex', 'fish-shell Documentation',
'fish-shell developers', 'manual'),
(
master_doc,
"fish-shell.tex",
"fish-shell Documentation",
"fish-shell developers",
"manual",
)
]
# -- Options for manual page output ------------------------------------------
def get_command_description(path, name):
""" Return the description for a command, by parsing its synopsis line """
with open(path) as fd:
for line in fd:
if line.startswith(name + " - "):
_, desc = line.split(' - ', 1)
_, desc = line.split(" - ", 1)
return desc.strip()
raise SphinxWarning('No description in file %s' % os.path.basename(path))
raise SphinxWarning("No description in file %s" % os.path.basename(path))
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'fish', 'fish-shell Documentation',
[author], 1)
]
for path in sorted(glob.glob('cmds/*')):
man_pages = [(master_doc, "fish", "fish-shell Documentation", [author], 1)]
for path in sorted(glob.glob("cmds/*")):
docname = strip_ext(path)
cmd = os.path.basename(docname)
man_pages.append((docname, cmd, get_command_description(path, cmd), '', 1))
man_pages.append((docname, cmd, get_command_description(path, cmd), "", 1))
# -- Options for Texinfo output ----------------------------------------------
@ -188,9 +190,15 @@ for path in sorted(glob.glob('cmds/*')):
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'fish-shell', 'fish-shell Documentation',
author, 'fish-shell', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"fish-shell",
"fish-shell Documentation",
author,
"fish-shell",
"One line description of project.",
"Miscellaneous",
)
]
@ -209,7 +217,7 @@ epub_title = project
# epub_uid = ''
# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]
# Disable smart-quotes to prevent double dashes from becoming emdashes.
smartquotes = False

View File

@ -91,9 +91,9 @@ def tokenize_fish_command(code, offset):
stdout=subprocess.PIPE,
universal_newlines=False,
)
stdout, _ = proc.communicate(code.encode('utf-8'))
stdout, _ = proc.communicate(code.encode("utf-8"))
result = []
for line in stdout.decode('utf-8').splitlines():
for line in stdout.decode("utf-8").splitlines():
start, end, role = line.split(",")
start, end = int(start), int(end)
value = code[start:end]

View File

@ -19,8 +19,8 @@
#include <errno.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <algorithm>

View File

@ -59,14 +59,11 @@ struct argparse_cmd_opts_t {
};
static const wchar_t *const short_options = L"+:hn:six:N:X:";
static const struct woption long_options[] = {{L"stop-nonopt", no_argument, NULL, 's'},
{L"ignore-unknown", no_argument, NULL, 'i'},
{L"name", required_argument, NULL, 'n'},
{L"exclusive", required_argument, NULL, 'x'},
{L"help", no_argument, NULL, 'h'},
{L"min-args", required_argument, NULL, 'N'},
{L"max-args", required_argument, NULL, 'X'},
{NULL, 0, NULL, 0}};
static const struct woption long_options[] = {
{L"stop-nonopt", no_argument, NULL, 's'}, {L"ignore-unknown", no_argument, NULL, 'i'},
{L"name", required_argument, NULL, 'n'}, {L"exclusive", required_argument, NULL, 'x'},
{L"help", no_argument, NULL, 'h'}, {L"min-args", required_argument, NULL, 'N'},
{L"max-args", required_argument, NULL, 'X'}, {NULL, 0, NULL, 0}};
// Check if any pair of mutually exclusive options was seen. Note that since every option must have
// a short name we only need to check those.
@ -584,12 +581,12 @@ static int argparse_parse_flags(parser_t &parser, argparse_cmd_opts_t &opts,
// A non-option argument.
// We use `-` as the first option-string-char to disable GNU getopt's reordering,
// otherwise we'd get ignored options first and normal arguments later.
// E.g. `argparse -i -- -t tango -w` needs to keep `-t tango -w` in $argv, not `-t -w tango`.
// E.g. `argparse -i -- -t tango -w` needs to keep `-t tango -w` in $argv, not `-t -w
// tango`.
opts.argv.push_back(argv[w.woptind - 1]);
continue;
}
// It's a recognized flag.
auto found = opts.options.find(opt);
assert(found != opts.options.end());
@ -610,7 +607,8 @@ static int argparse_parse_args(argparse_cmd_opts_t &opts, const wcstring_list_t
parser_t &parser, io_streams_t &streams) {
if (args.empty()) return STATUS_CMD_OK;
// "+" means stop at nonopt, "-" means give nonoptions the option character code `1`, and don't reorder.
// "+" means stop at nonopt, "-" means give nonoptions the option character code `1`, and don't
// reorder.
wcstring short_options = opts.stop_nonopt ? L"+:" : L"-";
std::vector<woption> long_options;
populate_option_strings(opts, &short_options, &long_options);

View File

@ -52,7 +52,7 @@ struct bind_cmd_opts_t {
/// List a single key binding.
/// Returns false if no binding with that sequence and mode exists.
bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user,
io_streams_t &streams) {
io_streams_t &streams) {
wcstring_list_t ecmds;
wcstring sets_mode;
@ -102,8 +102,8 @@ bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bo
// Overload with both kinds of bindings.
// Returns false only if neither exists.
bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset,
io_streams_t &streams) {
bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user,
bool preset, io_streams_t &streams) {
bool retval = false;
if (preset) {
retval |= list_one(seq, bind_mode, false, streams);
@ -151,7 +151,8 @@ void builtin_bind_t::function_names(io_streams_t &streams) {
}
/// Wraps input_terminfo_get_sequence(), appending the correct error messages as needed.
bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq, io_streams_t &streams) {
bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq,
io_streams_t &streams) {
if (input_terminfo_get_sequence(seq, out_seq)) {
return true;
}
@ -159,7 +160,8 @@ bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq
wcstring eseq = escape_string(seq, 0);
if (!opts->silent) {
if (errno == ENOENT) {
streams.err.append_format(_(L"%ls: No key with name '%ls' found\n"), L"bind", eseq.c_str());
streams.err.append_format(_(L"%ls: No key with name '%ls' found\n"), L"bind",
eseq.c_str());
} else if (errno == EILSEQ) {
streams.err.append_format(_(L"%ls: Key with name '%ls' does not have any mapping\n"),
L"bind", eseq.c_str());
@ -174,7 +176,7 @@ bool builtin_bind_t::get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq
/// Add specified key binding.
bool builtin_bind_t::add(const wchar_t *seq, const wchar_t *const *cmds, size_t cmds_len,
const wchar_t *mode, const wchar_t *sets_mode, bool terminfo, bool user,
io_streams_t &streams) {
io_streams_t &streams) {
if (terminfo) {
wcstring seq2;
if (get_terminfo_sequence(seq, &seq2, streams)) {
@ -202,8 +204,8 @@ bool builtin_bind_t::add(const wchar_t *seq, const wchar_t *const *cmds, size_t
/// @param use_terminfo
/// Whether to look use terminfo -k name
///
bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo, bool user,
io_streams_t &streams) {
bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo,
bool user, io_streams_t &streams) {
if (all) {
input_mapping_clear(mode, user);
return false;
@ -228,8 +230,7 @@ bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool us
return res;
}
bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv,
io_streams_t &streams) {
bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int arg_count = argc - optind;
@ -242,8 +243,9 @@ bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv,
} else {
// Inserting both on the other hand makes no sense.
if (opts->have_preset && opts->have_user) {
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd,
L"--preset and --user can not be used together when inserting bindings.");
streams.err.append_format(
BUILTIN_ERR_COMBO2, cmd,
L"--preset and --user can not be used together when inserting bindings.");
return true;
}
}
@ -314,7 +316,7 @@ void builtin_bind_t::list_modes(io_streams_t &streams) {
}
int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
static const wchar_t *const short_options = L":aehkKfM:Lm:s";
static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'},

View File

@ -11,30 +11,30 @@ struct io_streams_t;
struct bind_cmd_opts_t;
class builtin_bind_t {
public:
int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv);
private:
bind_cmd_opts_t *opts;
public:
int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv);
void list(const wchar_t *bind_mode, bool user, io_streams_t &streams);
void key_names(bool all, io_streams_t &streams);
void function_names(io_streams_t &streams);
bool add(const wchar_t *seq, const wchar_t *const *cmds, size_t cmds_len,
const wchar_t *mode, const wchar_t *sets_mode, bool terminfo, bool user,
io_streams_t &streams);
bool erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo, bool user,
io_streams_t &streams);
bool get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq, io_streams_t &streams);
bool insert(int optind, int argc, wchar_t **argv,
io_streams_t &streams);
void list_modes(io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, io_streams_t &streams);
private:
bind_cmd_opts_t *opts;
void list(const wchar_t *bind_mode, bool user, io_streams_t &streams);
void key_names(bool all, io_streams_t &streams);
void function_names(io_streams_t &streams);
bool add(const wchar_t *seq, const wchar_t *const *cmds, size_t cmds_len, const wchar_t *mode,
const wchar_t *sets_mode, bool terminfo, bool user, io_streams_t &streams);
bool erase(wchar_t **seq, bool all, const wchar_t *mode, bool use_terminfo, bool user,
io_streams_t &streams);
bool get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq, io_streams_t &streams);
bool insert(int optind, int argc, wchar_t **argv, io_streams_t &streams);
void list_modes(io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset,
io_streams_t &streams);
};
inline int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
builtin_bind_t bind;
return bind.builtin_bind(parser, streams, argv);
builtin_bind_t bind;
return bind.builtin_bind(parser, streams, argv);
}
#endif

View File

@ -20,10 +20,10 @@ struct builtin_cmd_opts_t {
bool query = false;
};
static const wchar_t *const short_options = L":hnq";
static const struct woption long_options[] = {
{L"help", no_argument, NULL, 'h'}, {L"names", no_argument, NULL, 'n'},
{L"query", no_argument, NULL, 'q'},
{NULL, 0, NULL, 0}};
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{L"names", no_argument, NULL, 'n'},
{L"query", no_argument, NULL, 'q'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {

View File

@ -102,7 +102,7 @@ int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (!opts.quiet) streams.out.append_format(L"%ls\n", path.c_str());
++found;
}
} else { // Either find_path explicitly or just quiet.
} else { // Either find_path explicitly or just quiet.
wcstring path;
if (path_get_path(command_name, &path, parser.vars())) {
if (!opts.quiet) streams.out.append_format(L"%ls\n", path.c_str());

View File

@ -2,8 +2,8 @@
#ifndef FISH_BUILTIN_COMMANDLINE_H
#define FISH_BUILTIN_COMMANDLINE_H
#include <cwchar>
#include <cstring>
#include <cwchar>
class parser_t;

View File

@ -263,7 +263,6 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Use one left-over arg as the do-complete argument
// to enable `complete -C "git check"`.
if (do_complete && !have_do_complete_param && argc == w.woptind + 1) {
do_complete_param = argv[argc - 1];
have_do_complete_param = true;
} else {
@ -306,7 +305,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (do_complete) {
if (!have_do_complete_param) {
// No argument given, try to use the current commandline.
const wchar_t* cmd = reader_get_buffer();
const wchar_t *cmd = reader_get_buffer();
if (cmd == NULL) {
// This corresponds to using 'complete -C' in non-interactive mode.
// See #2361 .

View File

@ -18,7 +18,7 @@ struct echo_cmd_opts_t {
bool interpret_special_chars = false;
};
static const wchar_t *const short_options = L"+:Eens";
static const struct woption * const long_options = NULL;
static const struct woption *const long_options = NULL;
static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv,
parser_t &parser, io_streams_t &streams) {
@ -89,7 +89,9 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base) {
return 6;
case L'7':
return 7;
default: { break; }
default: {
break;
}
}
if (base != 16) return UINT_MAX;
@ -117,7 +119,9 @@ static unsigned int builtin_echo_digit(wchar_t wc, unsigned int base) {
case L'f':
case L'F':
return 15;
default: { break; }
default: {
break;
}
}
return UINT_MAX;

View File

@ -99,7 +99,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
}
const wcstring ft = tok_first(job->command());
//For compatibility with fish 2.0's $_, now replaced with `status current-command`
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
if (!ft.empty()) parser.vars().set_one(L"_", ENV_EXPORT, ft);
reader_write_title(job->command(), parser);

View File

@ -40,13 +40,18 @@ struct functions_cmd_opts_t {
wchar_t *description = NULL;
};
static const wchar_t *const short_options = L":HDacd:ehnqv";
static const struct woption long_options[] = {
{L"erase", no_argument, NULL, 'e'}, {L"description", required_argument, NULL, 'd'},
{L"names", no_argument, NULL, 'n'}, {L"all", no_argument, NULL, 'a'},
{L"help", no_argument, NULL, 'h'}, {L"query", no_argument, NULL, 'q'},
{L"copy", no_argument, NULL, 'c'}, {L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'}, {L"handlers", no_argument, NULL, 'H'},
{L"handlers-type", required_argument, NULL, 't'}, {NULL, 0, NULL, 0}};
static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'},
{L"description", required_argument, NULL, 'd'},
{L"names", no_argument, NULL, 'n'},
{L"all", no_argument, NULL, 'a'},
{L"help", no_argument, NULL, 'h'},
{L"query", no_argument, NULL, 'q'},
{L"copy", no_argument, NULL, 'c'},
{L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'},
{L"handlers", no_argument, NULL, 'H'},
{L"handlers-type", required_argument, NULL, 't'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
@ -327,9 +332,10 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
maybe_t<event_type_t> type_filter;
if (opts.handlers_type) {
type_filter = event_type_for_name(opts.handlers_type);
if (! type_filter) {
streams.err.append_format(_(L"%ls: Expected generic | variable | signal | exit | job-id for --handlers-type\n"),
cmd);
if (!type_filter) {
streams.err.append_format(_(L"%ls: Expected generic | variable | signal | exit | "
L"job-id for --handlers-type\n"),
cmd);
return STATUS_INVALID_ARGS;
}
}

View File

@ -68,8 +68,8 @@ static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t su
const wchar_t *subcmd_str1 = enum_to_str(*hist_cmd, hist_enum_map);
const wchar_t *subcmd_str2 = enum_to_str(sub_cmd, hist_enum_map);
std::swprintf(err_text, sizeof(err_text) / sizeof(wchar_t),
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
subcmd_str2);
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
subcmd_str2);
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd, err_text);
return false;
}

View File

@ -21,7 +21,7 @@ enum {
JOBS_PRINT_PID, // print pid of each process in job
JOBS_PRINT_COMMAND, // print command name of each process in job
JOBS_PRINT_GROUP, // print group id of job
JOBS_PRINT_NOTHING, // print nothing (exit status only)
JOBS_PRINT_NOTHING, // print nothing (exit status only)
};
/// Calculates the cpu usage (in percent) of the specified job.
@ -117,14 +117,13 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int print_last = 0;
static const wchar_t *const short_options = L":cghlpq";
static const struct woption long_options[] = {
{L"command", no_argument, NULL, 'c'},
{L"group", no_argument, NULL, 'g'},
{L"help", no_argument, NULL, 'h'},
{L"last", no_argument, NULL, 'l'},
{L"pid", no_argument, NULL, 'p'},
{L"quiet", no_argument, NULL, 'q'},
{nullptr, 0, NULL, 0}};
static const struct woption long_options[] = {{L"command", no_argument, NULL, 'c'},
{L"group", no_argument, NULL, 'g'},
{L"help", no_argument, NULL, 'h'},
{L"last", no_argument, NULL, 'l'},
{L"pid", no_argument, NULL, 'p'},
{L"quiet", no_argument, NULL, 'q'},
{nullptr, 0, NULL, 0}};
int opt;
wgetopter_t w;
@ -189,15 +188,16 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int jobId = -1;
jobId = fish_wcstoi(argv[i] + 1);
if (errno || jobId < -1) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid job id"), cmd, argv[i]);
streams.err.append_format(_(L"%ls: '%ls' is not a valid job id"), cmd,
argv[i]);
return STATUS_INVALID_ARGS;
}
j = job_t::from_job_id(jobId);
}
else {
} else {
int pid = fish_wcstoi(argv[i]);
if (errno || pid < 0) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid process id\n"), cmd, argv[i]);
streams.err.append_format(_(L"%ls: '%ls' is not a valid process id\n"), cmd,
argv[i]);
return STATUS_INVALID_ARGS;
}
j = job_t::from_pid(pid);
@ -215,7 +215,8 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
for (const auto &j : jobs()) {
// Ignore unconstructed jobs, i.e. ourself.
if (j->is_visible()) {
builtin_jobs_print(j.get(), mode, !found && !streams.out_is_redirected, streams);
builtin_jobs_print(j.get(), mode, !found && !streams.out_is_redirected,
streams);
found = true;
}
}

View File

@ -54,8 +54,8 @@ static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
} else {
opts.scale = fish_wcstoi(w.woptarg);
if (errno || opts.scale < 0 || opts.scale > 15) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid scale value\n"), cmd,
w.woptarg);
streams.err.append_format(_(L"%ls: '%ls' is not a valid scale value\n"),
cmd, w.woptarg);
return STATUS_INVALID_ARGS;
}
}
@ -129,19 +129,28 @@ static const wchar_t *math_get_arg(int *argidx, wchar_t **argv, wcstring *storag
return math_get_arg_argv(argidx, argv);
}
static const wchar_t *math_describe_error(te_error_t& error) {
static const wchar_t *math_describe_error(te_error_t &error) {
if (error.position == 0) return L"NO ERROR?!?";
switch(error.type) {
case TE_ERROR_NONE: DIE("Error has no position");
case TE_ERROR_UNKNOWN_VARIABLE: return _(L"Unknown variable");
case TE_ERROR_MISSING_CLOSING_PAREN: return _(L"Missing closing parenthesis");
case TE_ERROR_MISSING_OPENING_PAREN: return _(L"Missing opening parenthesis");
case TE_ERROR_TOO_FEW_ARGS: return _(L"Too few arguments");
case TE_ERROR_TOO_MANY_ARGS: return _(L"Too many arguments");
case TE_ERROR_MISSING_OPERATOR: return _(L"Missing operator");
case TE_ERROR_UNKNOWN: return _(L"Expression is bogus");
default: return L"Unknown error";
switch (error.type) {
case TE_ERROR_NONE:
DIE("Error has no position");
case TE_ERROR_UNKNOWN_VARIABLE:
return _(L"Unknown variable");
case TE_ERROR_MISSING_CLOSING_PAREN:
return _(L"Missing closing parenthesis");
case TE_ERROR_MISSING_OPENING_PAREN:
return _(L"Missing opening parenthesis");
case TE_ERROR_TOO_FEW_ARGS:
return _(L"Too few arguments");
case TE_ERROR_TOO_MANY_ARGS:
return _(L"Too many arguments");
case TE_ERROR_MISSING_OPERATOR:
return _(L"Missing operator");
case TE_ERROR_UNKNOWN:
return _(L"Expression is bogus");
default:
return L"Unknown error";
}
}
@ -212,7 +221,7 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_
} else {
streams.err.append_format(L"%ls: Error: %ls\n", cmd, math_describe_error(error));
streams.err.append_format(L"'%ls'\n", expression.c_str());
streams.err.append_format(L"%*ls%ls\n", error.position - 1, L" ",L"^");
streams.err.append_format(L"%*ls%ls\n", error.position - 1, L" ", L"^");
retval = STATUS_CMD_ERROR;
}
setlocale(LC_NUMERIC, saved_locale);

View File

@ -57,10 +57,10 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <cstring>
#include <sys/types.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include "builtin.h"
#include "common.h"
@ -93,7 +93,6 @@ struct builtin_printf_state_t {
void nonfatal_error(const wchar_t *fmt, ...);
void fatal_error(const wchar_t *format, ...);
long print_esc(const wchar_t *escstart, bool octal_0);
void print_esc_string(const wchar_t *str);
void print_esc_char(wchar_t c);
@ -161,7 +160,9 @@ static int hex_to_bin(const wchar_t &c) {
case L'F': {
return 15;
}
default: { return -1; }
default: {
return -1;
}
}
}
@ -191,7 +192,9 @@ static int octal_to_bin(wchar_t c) {
case L'7': {
return 7;
}
default: { return -1; }
default: {
return -1;
}
}
}
@ -472,7 +475,9 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
fmt.append(L"l");
break;
}
default: { break; }
default: {
break;
}
}
// Append the conversion itself.

View File

@ -13,7 +13,7 @@
#include "wutil.h" // IWYU pragma: keep
/// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default).
static const wchar_t * const short_options = L"LPh";
static const wchar_t *const short_options = L"LPh";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {

View File

@ -6,8 +6,8 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <algorithm>
@ -55,27 +55,25 @@ struct read_cmd_opts_t {
};
static const wchar_t *const short_options = L":ac:d:ghiLlm:n:p:sSuxzP:UR:LB";
static const struct woption long_options[] = {
{L"array", no_argument, NULL, 'a'},
{L"command", required_argument, NULL, 'c'},
{L"delimiter", required_argument, NULL, 'd'},
{L"export", no_argument, NULL, 'x'},
{L"global", no_argument, NULL, 'g'},
{L"help", no_argument, NULL, 'h'},
{L"line", no_argument, NULL, 'L'},
{L"local", no_argument, NULL, 'l'},
{L"mode-name", required_argument, NULL, 'm'},
{L"nchars", required_argument, NULL, 'n'},
{L"null", no_argument, NULL, 'z'},
{L"prompt", required_argument, NULL, 'p'},
{L"prompt-str", required_argument, NULL, 'P'},
{L"right-prompt", required_argument, NULL, 'R'},
{L"shell", no_argument, NULL, 'S'},
{L"silent", no_argument, NULL, 's'},
{L"unexport", no_argument, NULL, 'u'},
{L"universal", no_argument, NULL, 'U'},
{NULL, 0, NULL, 0}
};
static const struct woption long_options[] = {{L"array", no_argument, NULL, 'a'},
{L"command", required_argument, NULL, 'c'},
{L"delimiter", required_argument, NULL, 'd'},
{L"export", no_argument, NULL, 'x'},
{L"global", no_argument, NULL, 'g'},
{L"help", no_argument, NULL, 'h'},
{L"line", no_argument, NULL, 'L'},
{L"local", no_argument, NULL, 'l'},
{L"mode-name", required_argument, NULL, 'm'},
{L"nchars", required_argument, NULL, 'n'},
{L"null", no_argument, NULL, 'z'},
{L"prompt", required_argument, NULL, 'p'},
{L"prompt-str", required_argument, NULL, 'P'},
{L"right-prompt", required_argument, NULL, 'R'},
{L"shell", no_argument, NULL, 'S'},
{L"silent", no_argument, NULL, 's'},
{L"unexport", no_argument, NULL, 'u'},
{L"universal", no_argument, NULL, 'U'},
{NULL, 0, NULL, 0}};
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
@ -98,8 +96,9 @@ static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
break;
}
case 'i': {
streams.err.append_format(_(L"%ls: usage of -i for --silent is deprecated. Please use -s or --silent instead.\n"),
cmd);
streams.err.append_format(_(L"%ls: usage of -i for --silent is deprecated. Please "
L"use -s or --silent instead.\n"),
cmd);
return STATUS_INVALID_ARGS;
}
case L'g': {
@ -350,17 +349,20 @@ static int read_one_char_at_a_time(int fd, wcstring &buff, int nchars, bool spli
static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int argc,
const wchar_t *const *argv, parser_t &parser, io_streams_t &streams) {
if (opts.prompt && opts.prompt_str) {
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd, L"-p", L"-P");
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd,
L"-p", L"-P");
builtin_print_error_trailer(parser, streams.err, cmd);
return STATUS_INVALID_ARGS;
}
if (opts.have_delimiter && opts.one_line) {
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd, L"--delimiter", L"--line");
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd,
L"--delimiter", L"--line");
return STATUS_INVALID_ARGS;
}
if (opts.one_line && opts.split_null) {
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd, L"-z", L"--line");
streams.err.append_format(_(L"%ls: Options %ls and %ls cannot be used together\n"), cmd,
L"-z", L"--line");
return STATUS_INVALID_ARGS;
}
@ -449,22 +451,23 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
opts.shell = false;
}
wchar_t * const *var_ptr = argv;
auto vars_left = [&] () { return argv + argc - var_ptr; };
auto clear_remaining_vars = [&] () {
wchar_t *const *var_ptr = argv;
auto vars_left = [&]() { return argv + argc - var_ptr; };
auto clear_remaining_vars = [&]() {
while (vars_left()) {
parser.vars().set_empty(*var_ptr, opts.place);
++var_ptr;
}
};
// Normally, we either consume a line of input or all available input. But if we are reading a line at
// a time, we need a middle ground where we only consume as many lines as we need to fill the given vars.
// Normally, we either consume a line of input or all available input. But if we are reading a
// line at a time, we need a middle ground where we only consume as many lines as we need to
// fill the given vars.
do {
buff.clear();
// TODO: Determine if the original set of conditions for interactive reads should be reinstated:
// if (isatty(0) && streams.stdin_fd == STDIN_FILENO && !split_null) {
// TODO: Determine if the original set of conditions for interactive reads should be
// reinstated: if (isatty(0) && streams.stdin_fd == STDIN_FILENO && !split_null) {
int stream_stdin_is_a_tty = isatty(streams.stdin_fd);
if (stream_stdin_is_a_tty && !opts.split_null) {
// Read interactively using reader_readline(). This does not support splitting on null.
@ -474,7 +477,8 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
lseek(streams.stdin_fd, 0, SEEK_CUR) != -1) {
exit_res = read_in_chunks(streams.stdin_fd, buff, opts.split_null);
} else {
exit_res = read_one_char_at_a_time(streams.stdin_fd, buff, opts.nchars, opts.split_null);
exit_res =
read_one_char_at_a_time(streams.stdin_fd, buff, opts.nchars, opts.split_null);
}
if (exit_res != STATUS_CMD_OK) {
@ -496,7 +500,8 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Every character is a separate token with one wrinkle involving non-array mode where
// the final var gets the remaining characters as a single string.
size_t x = std::max(static_cast<size_t>(1), buff.size());
size_t n_splits = (opts.array || static_cast<size_t>(vars_left()) > x) ? x : vars_left();
size_t n_splits =
(opts.array || static_cast<size_t>(vars_left()) > x) ? x : vars_left();
wcstring_list_t chars;
chars.reserve(n_splits);
@ -563,7 +568,7 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// is set to the remaining string.
split_about(buff.begin(), buff.end(), opts.delimiter.begin(), opts.delimiter.end(),
&splits, argc - 1);
assert(splits.size() <= (size_t) vars_left());
assert(splits.size() <= (size_t)vars_left());
for (const auto &split : splits) {
vars.set_one(*var_ptr++, opts.place, split);
}

View File

@ -30,7 +30,7 @@ int builtin_realpath(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
return STATUS_CMD_OK;
}
if (optind + 1 != argc) { // TODO: allow arbitrary args. `realpath *` should print many paths
if (optind + 1 != argc) { // TODO: allow arbitrary args. `realpath *` should print many paths
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, cmd, 1, argc - optind);
builtin_print_help(parser, streams, cmd, streams.out);
return STATUS_INVALID_ARGS;

View File

@ -4,9 +4,9 @@
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <algorithm>
@ -304,8 +304,7 @@ static bool validate_path_warning_on_colons(const wchar_t *cmd,
}
static void handle_env_return(int retval, const wchar_t *cmd, const wchar_t *key,
io_streams_t &streams) {
io_streams_t &streams) {
switch (retval) {
case ENV_OK: {
break;
@ -317,19 +316,18 @@ static void handle_env_return(int retval, const wchar_t *cmd, const wchar_t *key
}
case ENV_SCOPE: {
streams.err.append_format(
_(L"%ls: Tried to modify the special variable '%ls' with the wrong scope\n"),
cmd, key);
_(L"%ls: Tried to modify the special variable '%ls' with the wrong scope\n"), cmd,
key);
break;
}
case ENV_INVALID: {
streams.err.append_format(
_(L"%ls: Tried to modify the special variable '%ls' to an invalid value\n"),
cmd, key);
_(L"%ls: Tried to modify the special variable '%ls' to an invalid value\n"), cmd,
key);
break;
}
case ENV_NOT_FOUND: {
streams.err.append_format(
_(L"%ls: The variable '%ls' does not exist\n"), cmd, key);
streams.err.append_format(_(L"%ls: The variable '%ls' does not exist\n"), cmd, key);
break;
}
default: {
@ -579,8 +577,7 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams
if (i >= 50 && i < vals.size() - 50) continue;
}
const wcstring value = vals[i];
const wcstring escaped_val =
escape_string(value, ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT);
const wcstring escaped_val = escape_string(value, ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT);
streams.out.append_format(_(L"$%ls[%d]: length=%d value=|%ls|\n"), var_name, i + 1,
value.size(), escaped_val.c_str());
}

View File

@ -65,12 +65,12 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// By the time this is called we should have initialized the curses subsystem.
assert(curses_initialized);
// Hack in missing italics and dim capabilities omitted from MacOS xterm-256color terminfo
// Helps Terminal.app/iTerm
#if __APPLE__
// Hack in missing italics and dim capabilities omitted from MacOS xterm-256color terminfo
// Helps Terminal.app/iTerm
#if __APPLE__
const auto term_prog = parser.vars().get(L"TERM_PROGRAM");
if (!term_prog.missing_or_empty() && (term_prog->as_string() == L"Apple_Terminal"
|| term_prog->as_string() == L"iTerm.app")) {
if (!term_prog.missing_or_empty() &&
(term_prog->as_string() == L"Apple_Terminal" || term_prog->as_string() == L"iTerm.app")) {
const auto term = parser.vars().get(L"TERM");
if (!term.missing_or_empty() && (term->as_string() == L"xterm-256color")) {
enter_italics_mode = sitm_esc;
@ -78,7 +78,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
enter_dim_mode = dim_esc;
}
}
#endif
#endif
// Variables used for parsing the argument list.
wchar_t *cmd = argv[0];

View File

@ -102,24 +102,25 @@ struct status_cmd_opts_t {
/// least until fish 3.0 and possibly longer to avoid breaking everyones config.fish and other
/// scripts.
static const wchar_t *const short_options = L":L:cbilfnhj:t";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{L"current-filename", no_argument, NULL, 'f'},
{L"current-line-number", no_argument, NULL, 'n'},
{L"filename", no_argument, NULL, 'f'},
{L"fish-path", no_argument, NULL, STATUS_FISH_PATH},
{L"is-block", no_argument, NULL, 'b'},
{L"is-command-substitution", no_argument, NULL, 'c'},
{L"is-full-job-control", no_argument, NULL, STATUS_IS_FULL_JOB_CTRL},
{L"is-interactive", no_argument, NULL, 'i'},
{L"is-interactive-job-control", no_argument, NULL, STATUS_IS_INTERACTIVE_JOB_CTRL},
{L"is-login", no_argument, NULL, 'l'},
{L"is-no-job-control", no_argument, NULL, STATUS_IS_NO_JOB_CTRL},
{L"job-control", required_argument, NULL, 'j'},
{L"level", required_argument, NULL, 'L'},
{L"line", no_argument, NULL, 'n'},
{L"line-number", no_argument, NULL, 'n'},
{L"print-stack-trace", no_argument, NULL, 't'},
{NULL, 0, NULL, 0}};
static const struct woption long_options[] = {
{L"help", no_argument, NULL, 'h'},
{L"current-filename", no_argument, NULL, 'f'},
{L"current-line-number", no_argument, NULL, 'n'},
{L"filename", no_argument, NULL, 'f'},
{L"fish-path", no_argument, NULL, STATUS_FISH_PATH},
{L"is-block", no_argument, NULL, 'b'},
{L"is-command-substitution", no_argument, NULL, 'c'},
{L"is-full-job-control", no_argument, NULL, STATUS_IS_FULL_JOB_CTRL},
{L"is-interactive", no_argument, NULL, 'i'},
{L"is-interactive-job-control", no_argument, NULL, STATUS_IS_INTERACTIVE_JOB_CTRL},
{L"is-login", no_argument, NULL, 'l'},
{L"is-no-job-control", no_argument, NULL, STATUS_IS_NO_JOB_CTRL},
{L"job-control", required_argument, NULL, 'j'},
{L"level", required_argument, NULL, 'L'},
{L"line", no_argument, NULL, 'n'},
{L"line-number", no_argument, NULL, 'n'},
{L"print-stack-trace", no_argument, NULL, 't'},
{NULL, 0, NULL, 0}};
/// Remember the status subcommand and disallow selecting more than one status subcommand.
static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_cmd_t sub_cmd,
@ -129,8 +130,8 @@ static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_c
const wchar_t *subcmd_str1 = enum_to_str(opts.status_cmd, status_enum_map);
const wchar_t *subcmd_str2 = enum_to_str(sub_cmd, status_enum_map);
std::swprintf(err_text, sizeof(err_text) / sizeof(wchar_t),
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
subcmd_str2);
_(L"you cannot do both '%ls' and '%ls' in the same invocation"), subcmd_str1,
subcmd_str2);
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd, err_text);
return false;
}

View File

@ -11,8 +11,8 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <cwctype>

View File

@ -5,12 +5,12 @@
#include <errno.h>
#include <stdarg.h>
#include <cstring>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include <cmath>
#include <memory>
@ -24,8 +24,8 @@
#include "parser.h"
#include "wutil.h" // IWYU pragma: keep
using std::unique_ptr;
using std::move;
using std::unique_ptr;
namespace {
namespace test_expressions {
@ -530,7 +530,9 @@ unique_ptr<expression> test_parser::parse_expression(unsigned int start, unsigne
case 4: {
return parse_4_arg_expression(start, end);
}
default: { return parse_combining_expression(start, end); }
default: {
return parse_combining_expression(start, end);
}
}
}
@ -673,8 +675,8 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t
// We could not parse a float or an int.
// Check for special fish_wcsto* value or show standard EINVAL/ERANGE error.
if (errno == -1) {
errors.push_back(format_string(_(L"Integer %lld in '%ls' followed by non-digit"),
integral, argcs));
errors.push_back(
format_string(_(L"Integer %lld in '%ls' followed by non-digit"), integral, argcs));
} else {
errors.push_back(format_string(L"%s: '%ls'", std::strerror(errno), argcs));
}

View File

@ -79,7 +79,9 @@ static int parse_hex_digit(wchar_t x) {
case L'F': {
return 0xF;
}
default: { return -1; }
default: {
return -1;
}
}
}
@ -329,7 +331,9 @@ wcstring rgb_color_t::description() const {
case type_normal: {
return L"normal";
}
default: { break; }
default: {
break;
}
}
DIE("unknown color type");
}

View File

@ -14,13 +14,13 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h>
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
@ -63,7 +63,7 @@ constexpr wint_t NOT_A_WCHAR = static_cast<wint_t>(WEOF);
struct termios shell_modes;
/// This allows us to determine if we're running on the main thread
static std::atomic<size_t> thread_id { 0 };
static std::atomic<size_t> thread_id{0};
/// This allows us to notice when we've forked.
static relaxed_atomic_bool_t is_forked_proc{false};
/// This allows us to bypass the main thread checks
@ -168,8 +168,10 @@ bool is_windows_subsystem_for_linux() {
if (std::strstr(info.release, "Microsoft") != nullptr) {
const char *dash = std::strchr(info.release, '-');
if (dash == nullptr || strtod(dash + 1, nullptr) < 17763) {
debug(1, "This version of WSL is not supported and fish will probably not work correctly!\n"
"Please upgrade to Windows 10 1809 (17763) or higher to use fish!");
debug(1,
"This version of WSL is not supported and fish will probably not work "
"correctly!\n"
"Please upgrade to Windows 10 1809 (17763) or higher to use fish!");
}
return true;
@ -187,8 +189,8 @@ bool is_windows_subsystem_for_linux() {
#ifdef HAVE_BACKTRACE_SYMBOLS
// This function produces a stack backtrace with demangled function & method names. It is based on
// https://gist.github.com/fmela/591333 but adapted to the style of the fish project.
[[gnu::noinline]] static const wcstring_list_t
demangled_backtrace(int max_frames, int skip_levels) {
[[gnu::noinline]] static const wcstring_list_t demangled_backtrace(int max_frames,
int skip_levels) {
void *callstack[128];
const int n_max_frames = sizeof(callstack) / sizeof(callstack[0]);
int n_frames = backtrace(callstack, n_max_frames);
@ -576,9 +578,9 @@ void fish_setlocale() {
if (is_windows_subsystem_for_linux()) {
// neither of \u23CE and \u25CF can be displayed in the default fonts on Windows, though
// they can be *encoded* just fine. Use alternative glyphs.
omitted_newline_str = L"\u00b6"; // "pilcrow"
omitted_newline_str = L"\u00b6"; // "pilcrow"
omitted_newline_width = 1;
obfuscation_read_char = L'\u2022'; // "bullet"
obfuscation_read_char = L'\u2022'; // "bullet"
} else if (is_console_session()) {
omitted_newline_str = L"^J";
omitted_newline_width = 2;
@ -653,8 +655,8 @@ static void debug_shared(const wchar_t level, const wcstring &msg) {
std::fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str());
} else {
current_pid = getpid();
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid,
msg.c_str());
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name,
current_pid, msg.c_str());
}
}
@ -1139,7 +1141,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring
/// \param in is the raw string to be searched for literally when substituted in a PCRE2 expression.
static wcstring escape_string_pcre2(const wcstring &in) {
wcstring out;
out.reserve(in.size() * 1.3); // a wild guess
out.reserve(in.size() * 1.3); // a wild guess
for (auto c : in) {
switch (c) {
@ -1156,8 +1158,9 @@ static wcstring escape_string_pcre2(const wcstring &in) {
case L'}':
case L'\\':
case L'|':
// these two only *need* to be escaped within a character class, and technically it makes
// no sense to ever use process substitution output to compose a character class, but...
// these two only *need* to be escaped within a character class, and technically it
// makes no sense to ever use process substitution output to compose a character class,
// but...
case L'-':
case L']':
out.push_back('\\');
@ -1652,7 +1655,9 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
}
break;
}
default: { break; }
default: {
break;
}
}
}
@ -2232,9 +2237,7 @@ void set_main_thread() {
void configure_thread_assertions_for_testing() { thread_asserts_cfg_for_testing = true; }
bool is_forked_child() {
return is_forked_proc;
}
bool is_forked_child() { return is_forked_proc; }
void setup_fork_guards() {
is_forked_proc = false;
@ -2426,12 +2429,11 @@ std::string get_executable_path(const char *argv0) {
// Linux compatibility layer. Per sysctl(3), passing in a process ID of -1 returns
// the value for the current process.
size_t buff_size = sizeof buff;
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
int result = sysctl(name, sizeof(name) / sizeof(int), buff, &buff_size, nullptr, 0);
if (result != 0) {
wperror(L"sysctl KERN_PROC_PATHNAME");
}
else {
} else {
return std::string(buff);
}
#else
@ -2494,9 +2496,10 @@ bool is_console_session() {
const char *TERM = getenv("TERM");
return
// Test that the tty matches /dev/(console|dcons|tty[uv\d])
tty_name && ((strncmp(tty_name, "/dev/tty", len) == 0 &&
(tty_name[len] == 'u' || tty_name[len] == 'v' || isdigit(tty_name[len])))
|| strcmp(tty_name, "/dev/dcons") == 0 || strcmp(tty_name, "/dev/console") == 0)
tty_name &&
((strncmp(tty_name, "/dev/tty", len) == 0 &&
(tty_name[len] == 'u' || tty_name[len] == 'v' || isdigit(tty_name[len]))) ||
strcmp(tty_name, "/dev/dcons") == 0 || strcmp(tty_name, "/dev/console") == 0)
// and that $TERM is simple, e.g. `xterm` or `vt100`, not `xterm-something`
&& (!TERM || !strchr(TERM, '-') || !strcmp(TERM, "sun-color"));
}();

View File

@ -6,7 +6,7 @@
#include <errno.h>
#include <limits.h>
// Needed for va_list et al.
#include <stdarg.h> // IWYU pragma: keep
#include <stdarg.h> // IWYU pragma: keep
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> // IWYU pragma: keep
#endif
@ -248,7 +248,8 @@ extern const bool has_working_tty_timestamps;
[[noreturn]] void __fish_assert(const char *msg, const char *file, size_t line, int error);
/// Shorthand for wgettext call in situations where a C-style string is needed (e.g., std::fwprintf()).
/// Shorthand for wgettext call in situations where a C-style string is needed (e.g.,
/// std::fwprintf()).
#define _(wstr) wgettext(wstr).c_str()
/// Noop, used to tell xgettext that a string should be translated. Use this when a string cannot be
@ -348,26 +349,22 @@ class line_iterator_t {
// The current location in the iteration.
typename Collection::const_iterator current;
public:
public:
/// Construct from a collection (presumably std::string or std::wcstring).
line_iterator_t(const Collection &coll) : coll(coll), current(coll.cbegin()) {}
/// Access the storage in which the last line was stored.
const Collection &line() const {
return storage;
}
const Collection &line() const { return storage; }
/// Advances to the next line. \return true on success, false if we have exhausted the string.
bool next() {
if (current == coll.end())
return false;
if (current == coll.end()) return false;
auto newline_or_end = std::find(current, coll.cend(), '\n');
storage.assign(current, newline_or_end);
current = newline_or_end;
// Skip the newline.
if (current != coll.cend())
++current;
if (current != coll.cend()) ++current;
return true;
}
};
@ -531,7 +528,9 @@ inline bool bool_from_string(const std::string &x) {
}
}
inline bool bool_from_string(const wcstring &x) { return !x.empty() && std::wcschr(L"YTyt1", x.at(0)); }
inline bool bool_from_string(const wcstring &x) {
return !x.empty() && std::wcschr(L"YTyt1", x.at(0));
}
wchar_t **make_null_terminated_array(const wcstring_list_t &lst);
char **make_null_terminated_array(const std::vector<std::string> &lst);
@ -1014,16 +1013,14 @@ std::string get_executable_path(const char *fallback);
/// A RAII wrapper for resources that don't recur, so we don't have to create a separate RAII
/// wrapper for each function. Avoids needing to call "return cleanup()" or similar / everywhere.
struct cleanup_t {
private:
private:
const std::function<void()> cleanup;
public:
cleanup_t(std::function<void()> exit_actions)
: cleanup{std::move(exit_actions)} {}
~cleanup_t() {
cleanup();
}
public:
cleanup_t(std::function<void()> exit_actions) : cleanup{std::move(exit_actions)} {}
~cleanup_t() { cleanup(); }
};
bool is_console_session();
#endif // FISH_COMMON_H
#endif // FISH_COMMON_H

View File

@ -8,8 +8,8 @@
#include <pthread.h>
#include <pwd.h>
#include <stddef.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#include <algorithm>
#include <atomic>
@ -180,13 +180,9 @@ static bool compare_completions_by_order(const completion_entry_t &p1,
return p1.order < p2.order;
}
void completion_entry_t::add_option(const complete_entry_opt_t &opt) {
options.push_front(opt);
}
void completion_entry_t::add_option(const complete_entry_opt_t &opt) { options.push_front(opt); }
const option_list_t &completion_entry_t::get_options() const {
return options;
}
const option_list_t &completion_entry_t::get_options() const { return options; }
description_func_t const_desc(const wcstring &s) {
return [=](const wcstring &ignored) {
@ -202,7 +198,8 @@ static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_
if (flags & COMPLETE_AUTO_SPACE) {
new_flags &= ~COMPLETE_AUTO_SPACE;
size_t len = comp.size();
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0)) new_flags |= COMPLETE_NO_SPACE;
if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0))
new_flags |= COMPLETE_NO_SPACE;
}
return new_flags;
}

View File

@ -195,7 +195,6 @@ void append_completion(std::vector<completion_t> *completions, wcstring comp,
wcstring desc = wcstring(), int flags = 0,
string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact));
/// Support for "wrap targets." A wrap target is a command that completes like another command.
bool complete_add_wrapper(const wcstring &command, const wcstring &wrap_target);
bool complete_remove_wrapper(const wcstring &command, const wcstring &wrap_target);

View File

@ -306,9 +306,7 @@ struct var_stack_t {
}
/// Copy this vars_stack.
var_stack_t clone() const {
return var_stack_t(*this);
}
var_stack_t clone() const { return var_stack_t(*this); }
/// Snapshot this vars_stack. That is, return a new vars_stack that has copies of all local
/// variables. Note that this drops all shadowed nodes: only the currently executing function is
@ -610,7 +608,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
vars.set_empty(key_and_val, ENV_EXPORT | ENV_GLOBAL);
} else {
key.assign(key_and_val, 0, eql);
val.assign(key_and_val, eql+1, wcstring::npos);
val.assign(key_and_val, eql + 1, wcstring::npos);
if (is_read_only(key) || is_electric(key)) continue;
vars.set(key, ENV_EXPORT | ENV_GLOBAL, {val});
}
@ -722,7 +720,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
} else {
vars.set_pwd_from_getcwd();
}
vars.set_termsize(); // initialize the terminal size variables
vars.set_termsize(); // initialize the terminal size variables
// Set fish_bind_mode to "default".
vars.set_one(FISH_BIND_MODE_VAR, ENV_GLOBAL, DEFAULT_BIND_MODE);
@ -822,7 +820,8 @@ static void env_set_internal_universal(const wcstring &key, wcstring_list_t val,
/// * ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric
/// variables set from the local or universal scopes, or set as exported.
/// * ENV_INVALID, the variable value was invalid. This applies only to special variables.
int env_stack_t::set_internal(const wcstring &key, env_mode_flags_t input_var_mode, wcstring_list_t val) {
int env_stack_t::set_internal(const wcstring &key, env_mode_flags_t input_var_mode,
wcstring_list_t val) {
ASSERT_IS_MAIN_THREAD();
env_mode_flags_t var_mode = input_var_mode;
bool has_changed_old = vars_stack().has_changed_exported();

View File

@ -164,7 +164,7 @@ class env_var_t {
bool operator==(const env_var_t &rhs) const {
return *vals_ == *rhs.vals_ && flags_ == rhs.flags_;
}
bool operator!=(const env_var_t &rhs) const { return ! (*this == rhs); }
bool operator!=(const env_var_t &rhs) const { return !(*this == rhs); }
};
typedef std::map<wcstring, env_var_t> var_table_t;
@ -241,7 +241,6 @@ class env_stack_t final : public env_scoped_t {
env_stack_t(env_stack_t &&);
public:
/// Sets the variable with the specified name to the given values.
int set(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals);

View File

@ -24,8 +24,8 @@
#include <ncurses/term.h>
#endif
#include <algorithm>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <string>

View File

@ -43,8 +43,8 @@
#include "path.h"
#include "utf8.h"
#include "util.h" // IWYU pragma: keep
#include "wutil.h"
#include "wcstringutil.h"
#include "wutil.h"
#if __APPLE__
#define FISH_NOTIFYD_AVAILABLE 1
@ -229,7 +229,7 @@ static bool append_file_entry(env_var_t::env_var_flags_t flags, const wcstring &
}
/// Encoding of a null string.
static const wchar_t * const ENV_NULL = L"\x1d";
static const wchar_t *const ENV_NULL = L"\x1d";
/// Character used to separate arrays in universal variables file.
/// This is 30, the ASCII record separator.
@ -433,7 +433,8 @@ std::string env_universal_t::serialize_with_vars(const var_table_t &vars) {
// variable; soldier on.
const wcstring &key = kv.first;
const env_var_t &var = kv.second;
append_file_entry(var.get_flags(), key, encode_serialized(var.as_list()), &contents, &storage);
append_file_entry(var.get_flags(), key, encode_serialized(var.as_list()), &contents,
&storage);
}
return contents;
}
@ -902,7 +903,7 @@ void env_universal_t::parse_message_30_internal(const wcstring &msgstr, var_tabl
/// Parse message msg per fish 2.x format.
void env_universal_t::parse_message_2x_internal(const wcstring &msgstr, var_table_t *vars,
wcstring *storage) {
wcstring *storage) {
namespace f2x = fish2x_uvars;
const wchar_t *const msg = msgstr.c_str();
const wchar_t *cursor = msg;
@ -996,8 +997,9 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN]) { return
/// Function to get an identifier based on the hostname.
bool get_hostname_identifier(wcstring &result) {
//The behavior of gethostname if the buffer size is insufficient differs by implementation and libc version
//Work around this by using a "guaranteed" sufficient buffer size then truncating the result.
// The behavior of gethostname if the buffer size is insufficient differs by implementation and
// libc version Work around this by using a "guaranteed" sufficient buffer size then truncating
// the result.
bool success = false;
char hostname[256] = {};
if (gethostname(hostname, sizeof(hostname)) == 0) {

View File

@ -35,7 +35,7 @@ class pending_signals_t {
/// This is not accessed from a signal handler.
owning_lock<uint32_t> last_counter_{0};
public:
public:
pending_signals_t() = default;
/// No copying.
@ -64,7 +64,8 @@ public:
return {};
}
// The signal count has changed. Store the new counter and fetch all the signals that are set.
// The signal count has changed. Store the new counter and fetch all the signals that are
// set.
*current = count;
std::bitset<SIGNAL_COUNT> result{};
uint32_t bit = 0;
@ -183,7 +184,9 @@ wcstring event_get_desc(const event_t &evt) {
case event_type_t::generic: {
return format_string(_(L"handler for generic event '%ls'"), ed.str_param1.c_str());
}
case event_type_t::any: { DIE("Unreachable"); }
case event_type_t::any: {
DIE("Unreachable");
}
default:
DIE("Unknown event type");
}
@ -291,8 +294,7 @@ static void event_fire_internal(const event_t &event) {
void event_fire_delayed() {
ASSERT_IS_MAIN_THREAD();
// Do not invoke new event handlers from within event handlers.
if (is_event)
return;
if (is_event) return;
event_list_t to_send;
to_send.swap(blocked);
@ -301,7 +303,7 @@ void event_fire_delayed() {
// Append all signal events to to_send.
auto signals = s_pending_signals.acquire_pending();
if (signals.any()) {
for (uint32_t sig=0; sig < signals.size(); sig++) {
for (uint32_t sig = 0; sig < signals.size(); sig++) {
if (signals.test(sig)) {
auto e = std::make_shared<event_t>(event_type_t::signal);
e->desc.param1.signal = sig;
@ -368,7 +370,6 @@ static const wchar_t *event_name_for_type(event_type_t type) {
return L"";
}
void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
event_handler_list_t tmp = s_event_handlers;
std::sort(tmp.begin(), tmp.end(),
@ -401,8 +402,7 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
}
if (!last_type || *last_type != evt->desc.type) {
if (last_type)
streams.out.append(L"\n");
if (last_type) streams.out.append(L"\n");
last_type = static_cast<event_type_t>(evt->desc.type);
streams.out.append_format(L"Event %ls\n", event_name_for_type(*last_type));
}
@ -421,7 +421,8 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
streams.out.append_format(L"%ls %ls\n", evt->desc.str_param1.c_str(),
evt->function_name.c_str());
break;
case event_type_t::any: DIE("Unreachable");
case event_type_t::any:
DIE("Unreachable");
default:
streams.out.append_format(L"%ls\n", evt->function_name.c_str());
break;

View File

@ -14,9 +14,9 @@
#include <spawn.h>
#endif
#include <stdio.h>
#include <cstring>
#include <sys/wait.h>
#include <unistd.h>
#include <cstring>
#include <stack>
#include <algorithm>
@ -675,8 +675,8 @@ static bool handle_builtin_output(const std::shared_ptr<job_t> &j, process_t *p,
/// Executes an external command.
/// \return true on success, false if there is an exec error.
static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t> &j,
process_t *p, const io_chain_t &proc_io_chain) {
static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t> &j, process_t *p,
const io_chain_t &proc_io_chain) {
assert(p->type == process_type_t::external && "Process is not external");
// Get argv and envv before we fork.
null_terminated_array_t<char> argv_array;
@ -684,8 +684,7 @@ static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t
// Convert our IO chain to a dup2 sequence.
auto dup2s = dup2_list_t::resolve_chain(proc_io_chain);
if (! dup2s)
return false;
if (!dup2s) return false;
// Ensure that stdin is blocking before we hand it off (see issue #176). It's a
// little strange that we only do this with stdin and not with stdout or stderr.

View File

@ -7,10 +7,10 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h> // IWYU pragma: keep
@ -124,9 +124,7 @@ static void append_cmdsub_error(parse_error_list_t *errors, size_t source_start,
/// Test if the specified string does not contain character which can not be used inside a quoted
/// string.
static bool is_quotable(const wchar_t *str) {
return !std::wcspbrk(str, L"\n\t\r\b\x1B");
}
static bool is_quotable(const wchar_t *str) { return !std::wcspbrk(str, L"\n\t\r\b\x1B"); }
static bool is_quotable(const wcstring &str) { return is_quotable(str.c_str()); }
@ -168,7 +166,8 @@ wcstring expand_escape_variable(const env_var_t &var) {
/// Parse an array slicing specification Returns 0 on success. If a parse error occurs, returns the
/// index of the bad token. Note that 0 can never be a bad index because the string always starts
/// with [.
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx, size_t array_size) {
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx,
size_t array_size) {
const long size = (long)array_size;
size_t pos = 1; // skip past the opening square brace
@ -360,11 +359,12 @@ static bool expand_variables(wcstring instr, std::vector<completion_t> *out, siz
} else if (history) {
effective_val_count = history->size();
}
size_t bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list, effective_val_count);
size_t bad_pos =
parse_slice(in + slice_start, &slice_end, var_idx_list, effective_val_count);
if (bad_pos != 0) {
if (in[slice_start + bad_pos] == L'0') {
append_syntax_error(errors, slice_start + bad_pos,
L"array indices start at 1, not 0.");
L"array indices start at 1, not 0.");
} else {
append_syntax_error(errors, slice_start + bad_pos, L"Invalid index value");
}
@ -638,8 +638,7 @@ static bool expand_cmdsubst(wcstring input, parser_t &parser, std::vector<comple
wchar_t *slice_end;
size_t bad_pos;
bad_pos =
parse_slice(slice_begin, &slice_end, slice_idx, sub_res.size());
bad_pos = parse_slice(slice_begin, &slice_end, slice_idx, sub_res.size());
if (bad_pos != 0) {
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
return false;
@ -908,7 +907,7 @@ expand_result_t expander_t::stage_cmdsubst(wcstring input, std::vector<completio
append_completion(out, std::move(input));
break;
case 1: /* fallthroughs intentional */
append_cmdsub_error(errors, start, L"Command substitutions not allowed");
append_cmdsub_error(errors, start, L"Command substitutions not allowed");
case -1:
default:
return expand_result_t::error;
@ -1140,7 +1139,6 @@ expand_result_t expand_to_command_and_args(const wcstring &instr, const environm
parse_error_list_t *errors) {
// Fast path.
if (expand_is_clean(instr)) {
*out_cmd = instr;
return expand_result_t::ok;
}

View File

@ -14,13 +14,13 @@
#include <stdarg.h> // IWYU pragma: keep
#include <stdio.h> // IWYU pragma: keep
#include <stdlib.h>
#include <cstring>
#include <sys/stat.h> // IWYU pragma: keep
#include <sys/types.h> // IWYU pragma: keep
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <algorithm>
#include <cstring>
#include <cwchar>
#if HAVE_GETTEXT
#include <libintl.h>
#endif
@ -37,7 +37,7 @@
#include <ncurses/term.h>
#endif
#include <signal.h> // IWYU pragma: keep
#include <cwchar> // IWYU pragma: keep
#include <cwchar> // IWYU pragma: keep
#include "common.h" // IWYU pragma: keep
#include "fallback.h" // IWYU pragma: keep
@ -45,8 +45,8 @@
#if defined(TPARM_SOLARIS_KLUDGE)
#undef tparm
char *tparm_solaris_kludge(char *str, long p1, long p2, long p3, long p4,
long p5, long p6, long p7, long p8, long p9) {
char *tparm_solaris_kludge(char *str, long p1, long p2, long p3, long p4, long p5, long p6, long p7,
long p8, long p9) {
return tparm(str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
@ -97,8 +97,7 @@ int fish_mkstemp_cloexec(char *name_template) {
return wcscasecmp_fallback(a + 1, b + 1);
}
[[gnu::unused]] static int wcsncasecmp_fallback(const wchar_t *a, const wchar_t *b,
size_t count) {
[[gnu::unused]] static int wcsncasecmp_fallback(const wchar_t *a, const wchar_t *b, size_t count) {
if (count == 0) return 0;
if (*a == 0) {
@ -281,8 +280,10 @@ int fish_wcwidth(wchar_t wc) {
// (width 1) to an emoji (probably width 2). So treat it as width 1 so the sums work. See #2652.
// VS15 selects text presentation.
const wchar_t variation_selector_16 = L'\uFE0F', variation_selector_15 = L'\uFE0E';
if (wc == variation_selector_16) return 1;
else if (wc == variation_selector_15) return 0;
if (wc == variation_selector_16)
return 1;
else if (wc == variation_selector_15)
return 0;
// Korean Hangul Jamo median vowels and final consonants.
// These can either appear in combined form, taking 0 width themselves,
@ -403,4 +404,4 @@ double fish_compat::wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t lo
uselocale(prev_locale);
return ret;
}
#endif // defined(wcstod_l)
#endif // defined(wcstod_l)

View File

@ -196,8 +196,8 @@ int flock(int fd, int op);
#endif
// NetBSD _has_ wcstod_l, but it's doing some weak linking hullabaloo that I don't get.
// Since it doesn't have uselocale (yes, the standard function isn't there, the non-standard extension is),
// we can't try to use the fallback.
// Since it doesn't have uselocale (yes, the standard function isn't there, the non-standard
// extension is), we can't try to use the fallback.
#if !defined(HAVE_WCSTOD_L) && !defined(__NetBSD__)
// On some platforms if this is incorrectly detected and a system-defined
// defined version of `wcstod_l` exists, calling `wcstod` from our own
@ -207,7 +207,7 @@ int flock(int fd, int op);
// duplication.
#undef wcstod_l
namespace fish_compat {
double wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc);
double wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc);
}
#define wcstod_l(x, y, z) fish_compat::wcstod_l(x, y, z)
#endif

View File

@ -27,10 +27,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <memory>
@ -73,8 +73,8 @@ static const char *s_profiling_output_filename = NULL;
/// \return a timeval converted to milliseconds.
long long tv_to_msec(const struct timeval &tv) {
long long msec = (long long)tv.tv_sec * 1000; // milliseconds per second
msec += tv.tv_usec / 1000; // microseconds per millisecond
long long msec = (long long)tv.tv_sec * 1000; // milliseconds per second
msec += tv.tv_usec / 1000; // microseconds per millisecond
return msec;
}
@ -130,7 +130,9 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
#ifdef CMAKE_BINARY_DIR
// Detect if we're running right out of the CMAKE build directory
if (string_prefixes_string(CMAKE_BINARY_DIR, exec_path.c_str())) {
debug(2, "Running out of build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s", CMAKE_SOURCE_DIR);
debug(2,
"Running out of build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s",
CMAKE_SOURCE_DIR);
done = true;
paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share";
@ -249,7 +251,7 @@ int run_command_list(std::vector<std::string> *cmds, const io_chain_t &io) {
/// Parse the argument list, return the index of the first non-flag arguments.
static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
static const char * const short_opts = "+hPilnvc:C:p:d:f:D:";
static const char *const short_opts = "+hPilnvc:C:p:d:f:D:";
static const struct option long_opts[] = {{"command", required_argument, NULL, 'c'},
{"init-command", required_argument, NULL, 'C'},
{"features", required_argument, NULL, 'f'},
@ -339,7 +341,8 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"),
optarg);
exit(1);
}
break;

View File

@ -23,15 +23,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include <memory>
#include <string>
#include <vector>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include "color.h"
#include "common.h"
@ -62,7 +62,7 @@ static wcstring read_file(FILE *f) {
if (errno == EILSEQ) {
// Illegal byte sequence. Try to skip past it.
clearerr(f);
int ch = fgetc(f); // for printing the warning, and seeks forward 1 byte.
int ch = fgetc(f); // for printing the warning, and seeks forward 1 byte.
debug(1, "%s (byte=%X)", std::strerror(errno), ch);
ret = 1;
continue;
@ -119,8 +119,8 @@ struct prettifier_t {
line_continuation_indent = is_continuation ? 1 : 0;
}
// Append whitespace as necessary. If we have a newline, append the appropriate indent. Otherwise,
// append a space.
// Append whitespace as necessary. If we have a newline, append the appropriate indent.
// Otherwise, append a space.
void append_whitespace(indent_t node_indent) {
if (needs_continuation_newline) {
append_newline(true);
@ -131,7 +131,6 @@ struct prettifier_t {
output.append((node_indent + line_continuation_indent) * SPACES_PER_INDENT, L' ');
}
}
};
// Dump a parse tree node in a form helpful to someone debugging the behavior of this program.
@ -160,8 +159,9 @@ static void dump_node(indent_t node_indent, const parse_node_t &node, const wcst
nextc_str[2] = nextc + '@';
}
std::fwprintf(stderr, L"{off %4u, len %4u, indent %2u, kw %ls, %ls} [%ls|%ls|%ls]\n",
node.source_start, node.source_length, node_indent, keyword_description(node.keyword),
token_type_description(node.type), prevc_str, source_txt.c_str(), nextc_str);
node.source_start, node.source_length, node_indent,
keyword_description(node.keyword), token_type_description(node.type), prevc_str,
source_txt.c_str(), nextc_str);
}
void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t node_idx,
@ -185,16 +185,17 @@ void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t no
const parse_node_t &node = tree.at(node_idx);
const parse_token_type_t node_type = node.type;
const parse_token_type_t prev_node_type =
node_idx > 0 ? tree.at(node_idx - 1).type : token_type_invalid;
node_idx > 0 ? tree.at(node_idx - 1).type : token_type_invalid;
// Increment the indent if we are either a root job_list, or root case_item_list, or in an if or
// while header (#1665).
const bool is_root_job_list = node_type == symbol_job_list && parent_type != symbol_job_list;
// Increment the indent if we are either a root job_list, or root case_item_list, or in an
// if or while header (#1665).
const bool is_root_job_list =
node_type == symbol_job_list && parent_type != symbol_job_list;
const bool is_root_case_list =
node_type == symbol_case_item_list && parent_type != symbol_case_item_list;
node_type == symbol_case_item_list && parent_type != symbol_case_item_list;
const bool is_if_while_header =
(node_type == symbol_job_conjunction || node_type == symbol_andor_job_list) &&
(parent_type == symbol_if_clause || parent_type == symbol_while_header);
(node_type == symbol_job_conjunction || node_type == symbol_andor_job_list) &&
(parent_type == symbol_if_clause || parent_type == symbol_while_header);
if (is_root_job_list || is_root_case_list || is_if_while_header) {
node_indent += 1;
@ -253,7 +254,8 @@ void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t no
for (node_offset_t idx = node.child_count; idx > 0; idx--) {
// Note: We pass our type to our child, which becomes its parent node type.
// Note: While node.child_start could be -1 (NODE_OFFSET_INVALID) the addition is safe
// because we won't execute this call in that case since node.child_count should be zero.
// because we won't execute this call in that case since node.child_count should be
// zero.
pending_node_stack.push({node.child_start + (idx - 1), node_indent, node_type});
}
}
@ -435,7 +437,9 @@ static const wchar_t *html_class_name_for_color(highlight_spec_t spec) {
case highlight_role_t::selection: {
return P(selection);
}
default: { return P(other); }
default: {
return P(other);
}
}
}
@ -593,7 +597,8 @@ int main(int argc, char *argv[]) {
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"), optarg);
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"),
optarg);
exit(1);
}
break;
@ -612,8 +617,9 @@ int main(int argc, char *argv[]) {
wcstring src;
if (argc == 0) {
if (output_type == output_type_file) {
std::fwprintf(stderr, _(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
program_name);
std::fwprintf(stderr,
_(L"Expected file path to read/write for -w:\n\n $ %ls -w foo.fish\n"),
program_name);
exit(1);
}
src = read_file(stdin);
@ -661,7 +667,7 @@ int main(int argc, char *argv[]) {
exit(0);
} else {
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location,
std::strerror(errno));
std::strerror(errno));
exit(1);
}
break;

View File

@ -14,9 +14,9 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <termios.h>
#include <unistd.h>
#include <cstring>
#include <cwchar>
#include <memory>
@ -191,7 +191,8 @@ static double output_elapsed_time(double prev_tstamp, bool first_char_seen) {
if (delta_tstamp_us >= 1000000) {
std::fwprintf(stderr, L" ");
} else {
std::fwprintf(stderr, L"(%3lld.%03lld ms) ", delta_tstamp_us / 1000, delta_tstamp_us % 1000);
std::fwprintf(stderr, L"(%3lld.%03lld ms) ", delta_tstamp_us / 1000,
delta_tstamp_us % 1000);
}
return now;
}
@ -293,9 +294,10 @@ static void setup_and_process_keys(bool continuous_mode) {
if (continuous_mode) {
std::fwprintf(stderr, L"\n");
std::fwprintf(stderr, L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
std::fwprintf(stderr,
L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
std::fwprintf(stderr, L"or press [ctrl-%c] or [ctrl-%c] twice in a row.\n",
shell_modes.c_cc[VINTR] + 0x40, shell_modes.c_cc[VEOF] + 0x40);
shell_modes.c_cc[VINTR] + 0x40, shell_modes.c_cc[VEOF] + 0x40);
std::fwprintf(stderr, L"\n");
}

View File

@ -14,7 +14,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -23,8 +22,9 @@
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <cwchar>
#include <wctype.h>
#include <cstring>
#include <cwchar>
#include <thread>
#include <algorithm>
@ -494,7 +494,7 @@ static char *str2hex(const char *input) {
/// comes back through double conversion.
static void test_convert() {
int i;
std::vector<char> sb {};
std::vector<char> sb{};
say(L"Testing wide/narrow string conversion");
@ -612,10 +612,11 @@ static void test_tokenizer() {
}
if (types[i] != token.type) {
err(L"Tokenization error:");
std::fwprintf(stdout,
L"Token number %zu of string \n'%ls'\n, expected type %ld, got token type "
L"%ld\n",
i + 1, str, (long)types[i], (long)token.type);
std::fwprintf(
stdout,
L"Token number %zu of string \n'%ls'\n, expected type %ld, got token type "
L"%ld\n",
i + 1, str, (long)types[i], (long)token.type);
}
i++;
}
@ -734,9 +735,7 @@ static void test_pthread() {
say(L"Testing pthreads");
pthread_t result = {};
int val = 3;
bool made = make_pthread(&result, [&val](){
val += 2;
});
bool made = make_pthread(&result, [&val]() { val += 2; });
do_test(made);
void *ignore = nullptr;
int ret = pthread_join(result, &ignore);
@ -1900,18 +1899,20 @@ static void test_abbreviations() {
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// If commands should be expanded.
expanded = reader_expand_abbreviation_in_command(L"if gc", std::wcslen(L"if gc"), vars, &result);
expanded =
reader_expand_abbreviation_in_command(L"if gc", std::wcslen(L"if gc"), vars, &result);
if (!expanded) err(L"gc not expanded on line %ld", (long)__LINE__);
if (result != L"if git checkout")
err(L"gc incorrectly expanded on line %ld to '%ls'", (long)__LINE__, result.c_str());
// Others should not be.
expanded = reader_expand_abbreviation_in_command(L"of gc", std::wcslen(L"of gc"), vars, &result);
expanded =
reader_expand_abbreviation_in_command(L"of gc", std::wcslen(L"of gc"), vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
// Others should not be.
expanded =
reader_expand_abbreviation_in_command(L"command gc", std::wcslen(L"command gc"), vars, &result);
expanded = reader_expand_abbreviation_in_command(L"command gc", std::wcslen(L"command gc"),
vars, &result);
if (expanded) err(L"gc incorrectly expanded on line %ld", (long)__LINE__);
vars.pop();
@ -2055,11 +2056,11 @@ struct pager_layout_testcase_t {
wcstring text = sd.line(0).to_string();
if (text != expected) {
std::fwprintf(stderr, L"width %zu got %zu<%ls>, expected %zu<%ls>\n", this->width,
text.length(), text.c_str(), expected.length(), expected.c_str());
text.length(), text.c_str(), expected.length(), expected.c_str());
for (size_t i = 0; i < std::max(text.length(), expected.length()); i++) {
std::fwprintf(stderr, L"i %zu got <%lx> expected <%lx>\n", i,
i >= text.length() ? 0xffff : text[i],
i >= expected.length() ? 0xffff : expected[i]);
i >= text.length() ? 0xffff : text[i],
i >= expected.length() ? 0xffff : expected[i]);
}
}
do_test(text == expected);
@ -2252,8 +2253,7 @@ static bool run_one_test_test(int expected, wcstring_list_t &lst, bool bracket)
io_streams_t streams(0);
int result = builtin_test(parser, streams, argv);
if (expected != result)
err(L"expected builtin_test() to return %d, got %d", expected, result);
if (expected != result) err(L"expected builtin_test() to return %d, got %d", expected, result);
delete[] argv;
@ -2716,7 +2716,7 @@ static void test_1_completion(wcstring line, const wcstring &completion, complet
completion_apply_to_command_line(completion, flags, line, &cursor_pos, append_only);
if (result != expected) {
std::fwprintf(stderr, L"line %ld: %ls + %ls -> [%ls], expected [%ls]\n", source_line,
line.c_str(), completion.c_str(), result.c_str(), expected.c_str());
line.c_str(), completion.c_str(), result.c_str(), expected.c_str());
}
do_test(result == expected);
do_test(cursor_pos == out_cursor_pos);
@ -2759,15 +2759,15 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command, const wc
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n",
line, command.c_str());
do_test_from(!comps.empty(), line);
return;
} else if (!comps.empty() && expects_error) {
std::fwprintf(stderr,
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
do_test_from(comps.empty(), line);
}
@ -2795,15 +2795,15 @@ static void perform_one_completion_cd_test(const wcstring &command, const wcstri
bool expects_error = (expected == L"<error>");
if (comps.empty() && !expects_error) {
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n", line,
command.c_str());
std::fwprintf(stderr, L"line %ld: autosuggest_suggest_special() failed for command %ls\n",
line, command.c_str());
do_test_from(!comps.empty(), line);
return;
} else if (!comps.empty() && expects_error) {
std::fwprintf(stderr,
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
L"line %ld: autosuggest_suggest_special() was expected to fail but did not, "
L"for command %ls\n",
line, command.c_str());
do_test_from(comps.empty(), line);
}
@ -2813,9 +2813,9 @@ static void perform_one_completion_cd_test(const wcstring &command, const wcstri
if (suggestion.completion != expected) {
std::fwprintf(stderr,
L"line %ld: complete() for cd tab completion returned the wrong expected "
L"string for command %ls\n",
line, command.c_str());
L"line %ld: complete() for cd tab completion returned the wrong expected "
L"string for command %ls\n",
line, command.c_str());
std::fwprintf(stderr, L" actual: %ls\n", suggestion.completion.c_str());
std::fwprintf(stderr, L"expected: %ls\n", expected.c_str());
do_test_from(suggestion.completion == expected, line);
@ -2935,7 +2935,7 @@ static void perform_one_autosuggestion_should_ignore_test(const wcstring &comman
if (!comps.empty()) {
const wcstring &suggestion = comps.front().completion;
std::fwprintf(stderr, L"line %ld: complete() expected to return nothing for %ls\n", line,
command.c_str());
command.c_str());
std::fwprintf(stderr, L" instead got: %ls\n", suggestion.c_str());
}
}
@ -3194,8 +3194,8 @@ static void test_universal_callbacks() {
// Change uvars1.
uvars1.set(L"alpha", env_var_t{L"2", noflags}); // changes value
uvars1.set(L"beta", env_var_t{L"1", env_var_t::flag_export}); // changes export
uvars1.remove(L"delta"); // erases value
uvars1.set(L"epsilon", env_var_t{L"1", noflags}); // changes nothing
uvars1.remove(L"delta"); // erases value
uvars1.set(L"epsilon", env_var_t{L"1", noflags}); // changes nothing
uvars1.sync(callbacks);
// Change uvars2. It should treat its value as correct and ignore changes from uvars1.
@ -4547,7 +4547,7 @@ static void test_pcre2_escape() {
// all the following are intended to be ultimately matched literally - even if they don't look
// like that's the intent - so we escape them.
const wchar_t * const tests[][2] = {
const wchar_t *const tests[][2] = {
{L".ext", L"\\.ext"},
{L"{word}", L"\\{word\\}"},
{L"hola-mundo", L"hola\\-mundo"},
@ -4558,7 +4558,8 @@ static void test_pcre2_escape() {
for (const auto &test : tests) {
auto escaped = escape_string(test[0], 0, STRING_STYLE_REGEX);
if (escaped != test[1]) {
err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0], escaped.c_str(), test[1]);
err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0],
escaped.c_str(), test[1]);
}
}
}
@ -4947,9 +4948,9 @@ static void test_env_vars() {
env_var_t v2 = {wcstring_list_t{L"abc"}, env_var_t::flag_export};
env_var_t v3 = {wcstring_list_t{L"abc"}, 0};
env_var_t v4 = {wcstring_list_t{L"abc", L"def"}, env_var_t::flag_export};
do_test(v1 == v2 && ! (v1 != v2));
do_test(v1 != v3 && ! (v1 == v3));
do_test(v1 != v4 && ! (v1 == v4));
do_test(v1 == v2 && !(v1 != v2));
do_test(v1 != v3 && !(v1 == v3));
do_test(v1 != v4 && !(v1 == v4));
}
static void test_illegal_command_exit_code() {
@ -5211,8 +5212,8 @@ int main(int argc, char **argv) {
exit(-1);
}
if (!std::strcmp(wd, "/")) {
std::fwprintf(stderr,
L"Unable to find 'tests' directory, which should contain file test.fish\n");
std::fwprintf(
stderr, L"Unable to find 'tests' directory, which should contain file test.fish\n");
exit(EXIT_FAILURE);
}
if (chdir(dirname(wd)) < 0) {

View File

@ -8,7 +8,7 @@
// The contents of FISH-BUILD-VERSION-FILE looks like:
// FISH_BUILD_VERSION="2.7.1-62-gc0480092-dirty"
// Arrange for it to become a variable.
static const char * const
static const char *const
#include "FISH-BUILD-VERSION-FILE"
;
#endif

View File

@ -13,7 +13,8 @@ features_t &mutable_fish_features() { return global_features; }
const features_t::metadata_t features_t::metadata[features_t::flag_count] = {
{stderr_nocaret, L"stderr-nocaret", L"3.0", L"^ no longer redirects stderr"},
{qmark_noglob, L"qmark-noglob", L"3.0", L"? no longer globs"},
{string_replace_backslash, L"string-replace-fewer-backslashes", L"3.1", L"string replace -r needs fewer backslashes in the replacement"},
{string_replace_backslash, L"string-replace-fewer-backslashes", L"3.1",
L"string replace -r needs fewer backslashes in the replacement"},
};
const struct features_t::metadata_t *features_t::metadata_for(const wchar_t *name) {

View File

@ -8,26 +8,26 @@
#include "common.h"
class features_t {
public:
public:
/// The list of flags.
enum flag_t {
/// Whether ^ is supported for stderr redirection.
stderr_nocaret,
enum flag_t {
/// Whether ^ is supported for stderr redirection.
stderr_nocaret,
/// Whether ? is supported as a glob.
qmark_noglob,
/// Whether ? is supported as a glob.
qmark_noglob,
/// Whether string replace -r double-unescapes the replacement.
string_replace_backslash,
/// Whether string replace -r double-unescapes the replacement.
string_replace_backslash,
/// The number of flags.
flag_count
};
/// The number of flags.
flag_count
};
/// Return whether a flag is set.
bool test(flag_t f) const {
assert(f >= 0 && f < flag_count && "Invalid flag");
return values[f];
/// Return whether a flag is set.
bool test(flag_t f) const {
assert(f >= 0 && f < flag_count && "Invalid flag");
return values[f];
}
/// Set a flag.

View File

@ -696,7 +696,7 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
if (escaped_char == L'\\' || escaped_char == L'\'') {
colors[in_pos] = highlight_role_t::escape; // backslash
colors[in_pos + 1] = highlight_role_t::escape; // escaped char
in_pos += 1; // skip over backslash
in_pos += 1; // skip over backslash
}
}
} else if (c == L'\'') {
@ -723,7 +723,7 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
if (std::wcschr(L"\\\"\n$", escaped_char)) {
colors[in_pos] = highlight_role_t::escape; // backslash
colors[in_pos + 1] = highlight_role_t::escape; // escaped char
in_pos += 1; // skip over backslash
in_pos += 1; // skip over backslash
}
}
break;
@ -1247,7 +1247,9 @@ const highlighter_t::color_array_t &highlighter_t::highlight() {
this->color_node(node, highlight_role_t::comment);
break;
}
default: { break; }
default: {
break;
}
}
}

View File

@ -8,8 +8,8 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cstdint>
#include <cstring>
// We need the sys/file.h for the flock() declaration on Linux but not OS X.
#include <sys/file.h> // IWYU pragma: keep
#include <sys/mman.h>
@ -554,7 +554,6 @@ bool history_item_t::merge(const history_item_t &item) {
history_item_t::history_item_t(const wcstring &str, time_t when, history_identifier_t ident)
: creation_timestamp(when), identifier(ident) {
contents = trim(str);
contents_lower.reserve(contents.size());
for (const auto &c : contents) {
@ -1971,7 +1970,6 @@ void history_t::resolve_pending() {
this->has_pending_item = false;
}
static std::atomic<bool> private_mode{false};
void start_private_mode() {
@ -1981,6 +1979,4 @@ void start_private_mode() {
vars.set_one(L"fish_private_mode", ENV_GLOBAL, L"1");
}
bool in_private_mode() {
return private_mode.load();
}
bool in_private_mode() { return private_mode.load(); }

View File

@ -2,8 +2,8 @@
#include "config.h"
#include <errno.h>
#include <cwchar>
#include <wctype.h>
#include <cwchar>
#if HAVE_TERM_H
#include <curses.h>
#include <term.h>
@ -229,7 +229,7 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t *const *commands,
mapping_list_t &ml = user ? s_mapping_list : s_preset_mapping_list;
for (input_mapping_t& m : ml) {
for (input_mapping_t &m : ml) {
if (m.seq == sequence && m.mode == mode) {
m.commands = commands_vector;
m.sets_mode = sets_mode;
@ -289,7 +289,8 @@ void init_input() {
input_mapping_add(L"\x3", L"commandline ''", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x4", L"exit", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x5", L"bind", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x7f", L"backward-delete-char", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x7f", L"backward-delete-char", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE,
false);
// Arrows - can't have functions, so *-or-search isn't available.
input_mapping_add(L"\x1B[A", L"up-line", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
input_mapping_add(L"\x1B[B", L"down-line", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
@ -498,7 +499,9 @@ char_event_t input_readch(bool allow_commands) {
input_common_next_ch(evt);
return input_readch();
}
default: { return evt; }
default: {
return evt;
}
}
} else if (evt.is_eof()) {
// If we have EOF, we need to immediately quit.
@ -540,8 +543,7 @@ bool input_mapping_erase(const wcstring &sequence, const wcstring &mode, bool us
ASSERT_IS_MAIN_THREAD();
bool result = false;
mapping_list_t &ml = user ? s_mapping_list : s_preset_mapping_list;
for (std::vector<input_mapping_t>::iterator it = ml.begin(), end = ml.end();
it != end; ++it) {
for (std::vector<input_mapping_t>::iterator it = ml.begin(), end = ml.end(); it != end; ++it) {
if (sequence == it->seq && mode == it->mode) {
ml.erase(it);
result = true;
@ -551,8 +553,8 @@ bool input_mapping_erase(const wcstring &sequence, const wcstring &mode, bool us
return result;
}
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds, bool user,
wcstring *out_sets_mode) {
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds,
bool user, wcstring *out_sets_mode) {
bool result = false;
mapping_list_t &ml = user ? s_mapping_list : s_preset_mapping_list;
for (const input_mapping_t &m : ml) {
@ -571,52 +573,21 @@ static std::vector<terminfo_mapping_t> create_input_terminfo() {
assert(curses_initialized);
if (!cur_term) return {}; // setupterm() failed so we can't referency any key definitions
return {
TERMINFO_ADD(key_a1),
TERMINFO_ADD(key_a3),
TERMINFO_ADD(key_b2),
TERMINFO_ADD(key_backspace),
TERMINFO_ADD(key_beg),
TERMINFO_ADD(key_btab),
TERMINFO_ADD(key_c1),
TERMINFO_ADD(key_c3),
TERMINFO_ADD(key_cancel),
TERMINFO_ADD(key_catab),
TERMINFO_ADD(key_clear),
TERMINFO_ADD(key_close),
TERMINFO_ADD(key_command),
TERMINFO_ADD(key_copy),
TERMINFO_ADD(key_create),
TERMINFO_ADD(key_ctab),
TERMINFO_ADD(key_dc),
TERMINFO_ADD(key_dl),
TERMINFO_ADD(key_down),
TERMINFO_ADD(key_eic),
TERMINFO_ADD(key_end),
TERMINFO_ADD(key_enter),
TERMINFO_ADD(key_eol),
TERMINFO_ADD(key_eos),
TERMINFO_ADD(key_exit),
TERMINFO_ADD(key_f0),
TERMINFO_ADD(key_f1),
TERMINFO_ADD(key_f2),
TERMINFO_ADD(key_f3),
TERMINFO_ADD(key_f4),
TERMINFO_ADD(key_f5),
TERMINFO_ADD(key_f6),
TERMINFO_ADD(key_f7),
TERMINFO_ADD(key_f8),
TERMINFO_ADD(key_f9),
TERMINFO_ADD(key_f10),
TERMINFO_ADD(key_f11),
TERMINFO_ADD(key_f12),
TERMINFO_ADD(key_f13),
TERMINFO_ADD(key_f14),
TERMINFO_ADD(key_f15),
TERMINFO_ADD(key_f16),
TERMINFO_ADD(key_f17),
TERMINFO_ADD(key_f18),
TERMINFO_ADD(key_f19),
TERMINFO_ADD(key_f20),
TERMINFO_ADD(key_a1), TERMINFO_ADD(key_a3), TERMINFO_ADD(key_b2),
TERMINFO_ADD(key_backspace), TERMINFO_ADD(key_beg), TERMINFO_ADD(key_btab),
TERMINFO_ADD(key_c1), TERMINFO_ADD(key_c3), TERMINFO_ADD(key_cancel),
TERMINFO_ADD(key_catab), TERMINFO_ADD(key_clear), TERMINFO_ADD(key_close),
TERMINFO_ADD(key_command), TERMINFO_ADD(key_copy), TERMINFO_ADD(key_create),
TERMINFO_ADD(key_ctab), TERMINFO_ADD(key_dc), TERMINFO_ADD(key_dl),
TERMINFO_ADD(key_down), TERMINFO_ADD(key_eic), TERMINFO_ADD(key_end),
TERMINFO_ADD(key_enter), TERMINFO_ADD(key_eol), TERMINFO_ADD(key_eos),
TERMINFO_ADD(key_exit), TERMINFO_ADD(key_f0), TERMINFO_ADD(key_f1),
TERMINFO_ADD(key_f2), TERMINFO_ADD(key_f3), TERMINFO_ADD(key_f4), TERMINFO_ADD(key_f5),
TERMINFO_ADD(key_f6), TERMINFO_ADD(key_f7), TERMINFO_ADD(key_f8), TERMINFO_ADD(key_f9),
TERMINFO_ADD(key_f10), TERMINFO_ADD(key_f11), TERMINFO_ADD(key_f12),
TERMINFO_ADD(key_f13), TERMINFO_ADD(key_f14), TERMINFO_ADD(key_f15),
TERMINFO_ADD(key_f16), TERMINFO_ADD(key_f17), TERMINFO_ADD(key_f18),
TERMINFO_ADD(key_f19), TERMINFO_ADD(key_f20),
#if 0
// I know of no keyboard with more than 20 function keys, so adding the rest here makes very
// little sense, since it will take up a lot of room in any listings (like tab completions),
@ -665,66 +636,26 @@ static std::vector<terminfo_mapping_t> create_input_terminfo() {
TERMINFO_ADD(key_f62),
TERMINFO_ADD(key_f63),
#endif
TERMINFO_ADD(key_find),
TERMINFO_ADD(key_help),
TERMINFO_ADD(key_home),
TERMINFO_ADD(key_ic),
TERMINFO_ADD(key_il),
TERMINFO_ADD(key_left),
TERMINFO_ADD(key_ll),
TERMINFO_ADD(key_mark),
TERMINFO_ADD(key_message),
TERMINFO_ADD(key_move),
TERMINFO_ADD(key_next),
TERMINFO_ADD(key_npage),
TERMINFO_ADD(key_open),
TERMINFO_ADD(key_options),
TERMINFO_ADD(key_ppage),
TERMINFO_ADD(key_previous),
TERMINFO_ADD(key_print),
TERMINFO_ADD(key_redo),
TERMINFO_ADD(key_reference),
TERMINFO_ADD(key_refresh),
TERMINFO_ADD(key_replace),
TERMINFO_ADD(key_restart),
TERMINFO_ADD(key_resume),
TERMINFO_ADD(key_right),
TERMINFO_ADD(key_save),
TERMINFO_ADD(key_sbeg),
TERMINFO_ADD(key_scancel),
TERMINFO_ADD(key_scommand),
TERMINFO_ADD(key_scopy),
TERMINFO_ADD(key_screate),
TERMINFO_ADD(key_sdc),
TERMINFO_ADD(key_sdl),
TERMINFO_ADD(key_select),
TERMINFO_ADD(key_send),
TERMINFO_ADD(key_seol),
TERMINFO_ADD(key_sexit),
TERMINFO_ADD(key_sf),
TERMINFO_ADD(key_sfind),
TERMINFO_ADD(key_shelp),
TERMINFO_ADD(key_shome),
TERMINFO_ADD(key_sic),
TERMINFO_ADD(key_sleft),
TERMINFO_ADD(key_smessage),
TERMINFO_ADD(key_smove),
TERMINFO_ADD(key_snext),
TERMINFO_ADD(key_soptions),
TERMINFO_ADD(key_sprevious),
TERMINFO_ADD(key_sprint),
TERMINFO_ADD(key_sr),
TERMINFO_ADD(key_sredo),
TERMINFO_ADD(key_sreplace),
TERMINFO_ADD(key_sright),
TERMINFO_ADD(key_srsume),
TERMINFO_ADD(key_ssave),
TERMINFO_ADD(key_ssuspend),
TERMINFO_ADD(key_stab),
TERMINFO_ADD(key_sundo),
TERMINFO_ADD(key_suspend),
TERMINFO_ADD(key_undo),
TERMINFO_ADD(key_up)
TERMINFO_ADD(key_find), TERMINFO_ADD(key_help), TERMINFO_ADD(key_home),
TERMINFO_ADD(key_ic), TERMINFO_ADD(key_il), TERMINFO_ADD(key_left),
TERMINFO_ADD(key_ll), TERMINFO_ADD(key_mark), TERMINFO_ADD(key_message),
TERMINFO_ADD(key_move), TERMINFO_ADD(key_next), TERMINFO_ADD(key_npage),
TERMINFO_ADD(key_open), TERMINFO_ADD(key_options), TERMINFO_ADD(key_ppage),
TERMINFO_ADD(key_previous), TERMINFO_ADD(key_print), TERMINFO_ADD(key_redo),
TERMINFO_ADD(key_reference), TERMINFO_ADD(key_refresh), TERMINFO_ADD(key_replace),
TERMINFO_ADD(key_restart), TERMINFO_ADD(key_resume), TERMINFO_ADD(key_right),
TERMINFO_ADD(key_save), TERMINFO_ADD(key_sbeg), TERMINFO_ADD(key_scancel),
TERMINFO_ADD(key_scommand), TERMINFO_ADD(key_scopy), TERMINFO_ADD(key_screate),
TERMINFO_ADD(key_sdc), TERMINFO_ADD(key_sdl), TERMINFO_ADD(key_select),
TERMINFO_ADD(key_send), TERMINFO_ADD(key_seol), TERMINFO_ADD(key_sexit),
TERMINFO_ADD(key_sf), TERMINFO_ADD(key_sfind), TERMINFO_ADD(key_shelp),
TERMINFO_ADD(key_shome), TERMINFO_ADD(key_sic), TERMINFO_ADD(key_sleft),
TERMINFO_ADD(key_smessage), TERMINFO_ADD(key_smove), TERMINFO_ADD(key_snext),
TERMINFO_ADD(key_soptions), TERMINFO_ADD(key_sprevious), TERMINFO_ADD(key_sprint),
TERMINFO_ADD(key_sr), TERMINFO_ADD(key_sredo), TERMINFO_ADD(key_sreplace),
TERMINFO_ADD(key_sright), TERMINFO_ADD(key_srsume), TERMINFO_ADD(key_ssave),
TERMINFO_ADD(key_ssuspend), TERMINFO_ADD(key_stab), TERMINFO_ADD(key_sundo),
TERMINFO_ADD(key_suspend), TERMINFO_ADD(key_undo), TERMINFO_ADD(key_up)
};
}

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