~ubuntu-branches/ubuntu/karmic/zsh/karmic

« back to all changes in this revision

Viewing changes to Completion/Unix/Command/_perforce

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-06-02 10:40:25 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090602104025-lg6wynxpzqi08k2i
Tags: 4.3.10-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  + debian/zshrc: Enable completions by default, unless
    skip_global_compinit is set

Show diffs side-by-side

added added

removed removed

Lines of Context:
163
163
# File completion for some functions is restricted by the Perforce
164
164
# status of the file; for example, `p4 opened' only completes opened
165
165
# files (surprised?)  However, you can set the style (N.B. not tag)
166
 
# all-files; so, for example, you can turn off the limit in this case by
 
166
# `all-files'; so, for example, you can turn off the limit in this case by
167
167
#   zstyle ':completion:*:p4-opened:*' all-files true
168
 
# Normally the file-patterns style would be used to control matching,
 
168
# Normally the `file-patterns' style would be used to control matching,
169
169
# but as the file types are not selected by globbing it doesn't work here
170
170
# However, if you set the all-files style, all filename completion is done
171
 
# by the standard mechanism; in this case, the file-patterns style works
172
 
# as usual.  The style ignored-patterns is available in any case, even
173
 
# without all-files; this is therefore generally the one to use.
 
171
# by the standard mechanism; in this case, the `file-patterns' style works
 
172
# as usual.  The style `ignored-patterns' is available in any case, even
 
173
# without `all-files'; this is therefore generally the one to use.
 
174
#
 
175
# The style `whole-path' allows you complete the entire path to a file
 
176
# at once.  This is useful in cases such as opened files where the
 
177
# list of files is likely to be short but may include files with
 
178
# widely different paths.  As with the `glob' style, the tag is the
 
179
# Perforce disposition of the file: integrated, opened, resolved, dirs,
 
180
# files.  For example, with
 
181
#   zstyle ':completion:*:p4-revert:*:opened' whole-path true
 
182
# completion after `p4 revert' will offer you the entire depot path
 
183
# to a file rather than just part of the path at once (with the
 
184
# usual methods of disambiguation).  Directory completion is turned
 
185
# off during a `whole-path' completion.  The `whole-path' style can
 
186
# also take the value `absolute'; this means that an initial `/'
 
187
# activates `whole-path' completion, otherwise a relative file path
 
188
# will be completed in the normal way.  For example, with
 
189
#   zstyle ':completion:*:p4-revert:*:opened' whole-path absolute
 
190
# then after `p4 revert <TAB>' you are offered open files in the
 
191
# current directory plus directories; after `p4 revert /<TAB>' you
 
192
# are offered all open files in depot syntax.
174
193
#
175
194
# With `p4 diff', the shell will spot if you have used an option that
176
195
# allows you to diff unopened files (such as -f) and in that case offer
791
810
}
792
811
 
793
812
 
 
813
# Helper function for the helper function for the helper functions
 
814
# for the helper function _perforce_files.
 
815
#
 
816
# Check if we should do whole-path completion.
 
817
# The argument is the Perforce disposition of files are looking at.
 
818
_perforce_whole_path() {
 
819
  local wp
 
820
 
 
821
  zstyle -s ":completion:${curcontext}:$1" whole-path wp
 
822
  case $wp in
 
823
    (true|yes|on|1)
 
824
    return 0
 
825
    ;;
 
826
 
 
827
    (absolute)
 
828
    [[ ${(Q)PREFIX} = /* ]] && return 0
 
829
    ;;
 
830
  esac
 
831
 
 
832
  return 1
 
833
}
 
834
 
794
835
#
795
836
# Helper function for the helper functions for the helper function
796
837
# _perforce_files.  This is common code to retrieve a list of files
806
847
  local pfx
807
848
  local -a files
808
849
 
809
 
  if zstyle -t ":completion:${curcontext}:$1" glob; then
 
850
  if _perforce_whole_path $1; then
 
851
    files=(${${(f)"$(_perforce_call_p4 $1 $1 2>/dev/null)"}%%\#*})
 
852
  elif zstyle -t ":completion:${curcontext}:$1" glob; then
810
853
    # Limit the list by using Perforce to glob the pattern.
811
854
    # This may be faster, but won't use matcher specs etc.
812
855
    pfx=${(Q)PREFIX}
993
1036
  local dodirs unmaintained
994
1037
  # Suffix operations can modify context
995
1038
  local curcontext="$curcontext"
 
1039
  # Used to inhibit directory completion
 
1040
  local nodirs
996
1041
 
997
1042
  while (( $# )); do
998
1043
    if [[ $1 = -t(#b)(?) ]]; then
1030
1075
  # We might get into problems with characters recognised as
1031
1076
  # special by p4 files and p4 dirs, but worry about that later.
1032
1077
  pfx=${(Q)PREFIX}
 
1078
 
1033
1079
  if [[ -prefix *@ ]]; then
1034
1080
    # Modify context to indicate we are in a suffix.
1035
1081
    curcontext="${curcontext%:*}:at-suffix"
1072
1118
          ! zstyle -t ":completion:${curcontext}:" all-files; then
1073
1119
          for type in $types; do
1074
1120
            altfiles+=("$type-files:$type file:_perforce_${type}_files")
 
1121
            _perforce_whole_path $type && nodirs=1
1075
1122
          done
1076
1123
        else
1077
1124
          altfiles+=("depot-files:file in depot:_perforce_depot_files")
1078
1125
        fi
1079
1126
      fi
1080
 
      # Intermediate directories in a client view.
1081
 
      # See function for notes.
1082
 
      altfiles+=("client-dirs:client directory:_perforce_client_dirs")
 
1127
      if [[ -z $nodirs ]]; then
 
1128
        # Intermediate directories in a client view.
 
1129
        # See function for notes.
 
1130
        altfiles+=("client-dirs:client directory:_perforce_client_dirs")
 
1131
      fi
1083
1132
    fi
1084
1133
    altfiles+=("depot-dirs:directory in depot:_perforce_depot_dirs"
1085
1134
#      "subdirs:subdirectory search:_perforce_subdirs"
1118
1167
 
1119
1168
    for type in $types; do
1120
1169
      altfiles+=("$type-files:$type file:_perforce_${type}_files")
 
1170
      _perforce_whole_path $type && nodirs=1
1121
1171
    done
1122
1172
 
1123
 
#    altfiles+=("subdirs:subdirectory search:_perforce_subdirs")
1124
 
    if zstyle -t ":completion:${curcontext}:" depot-files; then
1125
 
      altfiles+=("depot-dirs:directory in depot:_perforce_depot_dirs")
1126
 
    else
1127
 
      altfiles+=("directories:directory:_path_files -/")
 
1173
    if [[ -z $nodirs ]]; then
 
1174
#      altfiles+=("subdirs:subdirectory search:_perforce_subdirs")
 
1175
      if zstyle -t ":completion:${curcontext}:" depot-files; then
 
1176
        altfiles+=("depot-dirs:directory in depot:_perforce_depot_dirs")
 
1177
      else
 
1178
        altfiles+=("directories:directory:_path_files -/")
 
1179
      fi
1128
1180
    fi
1129
1181
    _alternative $altfiles
1130
1182
  elif zstyle -t ":completion:${curcontext}:" depot-files; then