Last active
February 18, 2025 22:02
-
-
Save bitshifter/2df407fe8e71ad56e5af0511c1a9ace0 to your computer and use it in GitHub Desktop.
A Perforce custom completer for nushell (work in progress)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nushell version 0.93.0 | |
# some short flags cannot be added to extern completers due to this bug https://github.com/nushell/nushell/issues/8318 | |
# List Perforce help topics | |
def "nu-complete p4 help topics" [] { | |
[ | |
'add', | |
'annotate', | |
'client', | |
'clients', | |
'commands', | |
'copy', | |
'describe', | |
'delete', | |
'diff', | |
'diff2', | |
'edit', | |
'info', | |
'integrate', | |
'integrations', | |
'interchanges', | |
'help', | |
'labels', | |
'login', | |
'logout', | |
'merge', | |
'move', | |
'opened', | |
'populate', | |
'print', | |
'reconcile', | |
'resolve', | |
'revert', | |
'revisions', | |
'shelve', | |
'simple', | |
'streams', | |
'submit', | |
'switch', | |
'sync', | |
'undo', | |
'unshelve', | |
'update', | |
'user', | |
'users', | |
] | |
} | |
# Display the current user | |
def "nu-complete p4 current user" [] { | |
^p4 info | | |
lines | | |
parse '{label}: {value}' | | |
where label == "User name" | | |
get value | |
} | |
# Display the current client | |
def "nu-complete p4 current client" [] { | |
let client = ^p4 info | | |
lines | | |
parse '{label}: {value}' | | |
where label == "Client name" | | |
get value | |
if not ($client | is-empty) and not (^p4 clients -e ($client | to text) | is-empty) { | |
$client | |
} | |
} | |
# Display changelist statuses | |
def "nu-complete p4 changes statuses" [] { | |
['pending', 'shelved', 'submitted'] | |
} | |
# Display file types | |
def "nu-complete p4 filetypes" [] { | |
[ | |
'text', | |
'binary', | |
'symlink', | |
'apple', | |
'resource', | |
'unicode', | |
'utf8', | |
'utf16' | |
] | |
} | |
# List all users with the current user first | |
def "nu-complete p4 users" [] { | |
let users = ^p4 users | | |
lines | | |
parse '{user} <{email}> ({name}) accessed {accessed}' | | |
get user | |
nu-complete p4 current user | append $users | uniq | |
} | |
# Display list of clients with current client first | |
def "nu-complete p4 clients" [] { | |
let clients = ^p4 clients | | |
lines | | |
parse "Client {client} {date} root {root} '{description}'" | | |
get client | |
nu-complete p4 current client | append $clients | uniq | |
} | |
# Display list of pending changes for the current client | |
def "nu-complete p4 changes pending" [] { | |
^p4 changes -c (nu-complete p4 current client | to text) -s pending | | |
lines | | |
parse "Change {value} on {date} by {user}@{client} *{status}* '{description}'" | | |
select value description | |
} | |
# global opts | |
export extern "p4" [ | |
-c: string@"nu-complete p4 clients" # overrides any P4CLIENT setting with the specified client name | |
-d: string # overrides any PWD setting (current working directory) and replaces it with the specified directory | |
-I # specify that progress indicators, if available, are desired | |
-H: string # overrides any P4HOST setting and replaces it with the specified hostname | |
-p: string # overrides any P4PORT setting with the specified protocol:host:port | |
-P: string # enables a password (or ticket) to be passed on the command line | |
-r: number # specifies the number of times to retry a command (notably, p4 sync) if the network times out | |
-u: string@"nu-complete p4 users" # overrides any P4USER, USER, or USERNAME setting with the specified user name | |
-x: string # instructs Helix Server to read arguments, one per line, from the specified file | |
-C: string # overrides any P4CHARSET setting with the specified character set | |
-q # quiet mode, which suppresses informational messages and reports only warnings or errors | |
-v # debug modes | |
-V # displays the version of the p4 application and exits | |
-h # displays basic usage information and exits | |
] | |
# Print help message | |
export extern "p4 help" [ | |
topic?: string@"nu-complete p4 help topics" | |
] | |
# Open files for adding to the depot | |
export extern "p4 add" [ | |
...file: string # file(s) to add | |
-c: number@"nu-complete p4 changes pending" # opens files in the designated changelist instead of the default changelist | |
-f # add files with filenames that contain wildcard characters | |
-t: string@"nu-complete p4 filetypes" # specifies the filetype to use | |
-I # do not perform any ignore checking | |
-n # displays a preview of the add operation without changing any files or metadata | |
] | |
# Display list of pending and submitted changelists | |
export extern "p4 changes" [ | |
...file: string | |
-i # includes any changelists integrated into the specified files | |
-t # displays the time as well as the date | |
-l # displays the full text of the changelist descriptions | |
-L # displays the changelist descriptions, truncated to 250 characters if longer | |
-f # enables admin users to view restricted changes | |
-c: string@"nu-complete p4 clients" # limits changes to those on the named client | |
-e: number # displays only changes that are above and including the specified changelist number | |
-m: number # limits changes to the 'max' most recent | |
-r # sorts the output in reverse order | |
-s: string@"nu-complete p4 changes statuses" # limits the output to changelists with the specified status | |
-u: string@"nu-complete p4 users" # displays only changes owned by the specified user | |
--stream # displays only changes that contain a stream spec | |
--nostream # displays only changes that do not contain a stream spec | |
] | |
# Display list of clients | |
export extern "p4 clients" [ | |
-t # displays the time as well as the date | |
-u: string@"nu-complete p4 users" # lists client workspaces that are owned by the specified user | |
-e: string # lists workspaces with a name that matches the pattern | |
-m: number # limits output to the specified number of workspaces | |
-S: string # limits output to the client workspaces dedicated to the stream | |
-U # lists unloaded clients | |
-a # specifies that all clients should be displayed, not just those that are bound to this server | |
-s: string # specifies that only those clients bound to the specified server ID should be displayed | |
] | |
# Copy one set of files into another set of files, and/or copy one stream spec into another stream spec | |
export extern "p4 copy" [ | |
fromFile: string | |
toFile?: string | |
-c: number@"nu-complete p4 changes pending" # opens files in the designated changelist instead of the default changelist | |
-b: string # makes p4 copy use a user-defined branch view | |
-S: string # copy from a stream to its parent | |
-P: string # used with -S to generate the branch view using a parent stream other than the stream's actual parent | |
-F # used with -S to force copying against a stream's expected flow | |
-r # used with -S to reverse the copy direction | |
-f # forces creation of extra revisions to explicitly record that files have been copied | |
-n # displays a preview of the copy witout actually doing anything | |
-m: number # limits the actions to the first 'max' number of files | |
-q # suppresses normal output messages | |
-v # causes a virtual copy that does not modify client workspace files | |
] | |
# Open existing files for removal from the depot | |
export extern "p4 delete" [ | |
] | |
# Open existing files for editing | |
export extern "p4 edit" [ | |
...file: string # file(s) to add | |
-c: number@"nu-complete p4 changes pending" # opens files in the specified pending changelist instead of the default changelist | |
-t: string@"nu-complete p4 filetypes" # specifies the filetype to use | |
-n # previews the operation without changing any files or metadata | |
-k # updates metadata without transferring files to the workspace | |
--remote: string # useful for DVCS configurations in which files of type +l are in use | |
] | |
# Display client/server information | |
export extern "p4 info" [ | |
-s # produces 'short' output that omits any information that requires a database lookup such as the client root | |
] | |
# Synonym for 'sync -k' | |
export extern "p4 flush" [ | |
] | |
# Log in to Perforce by obtaining a session ticket | |
export extern "p4 login" [ | |
user?: string | |
-a # causes the server to issue a ticket that is valid on all host machines | |
-h: string # causes the server to issue a ticket that is valid on the specified host (IP address) | |
-p # displays the ticket, but does not store it on the client machine | |
-r: string # causes the server to forward the login to the server referenced in the specified remote specification | |
-s # displays the status of the current ticket | |
] | |
# List open files | |
export extern "p4 opened" [ | |
file?: string | |
-a # lists opened files in all clients | |
-C: string@"nu-complete p4 clients" # lists files open in the specified client workspace | |
-u: string@"nu-complete p4 users" # lists files opened by the specified user | |
-c: number@"nu-complete p4 changes pending" # lists files opened in the specified changelist | |
-m: number # limits output to the first 'max' number of files | |
-s # produces 'short' and optimized output when used with the -a (all clients) option | |
-x # lists files that are opened 'exclusive' | |
-g # lists files that are opened on the Commit Server in a distributed installation | |
] | |
# Resolve updates to open workspace files | |
export extern "p4 resolve" [ | |
-A # can be used to limit the kind of resolving that will be attempted (Aa, Ab, Ac, Ad, Am, At, AQ) | |
-a # puts 'p4 resolve' into automatic mode (as, am, af, at, ay) | |
-d # can be used to ignore whitespace and line endings when merging files (db, dw, dl) | |
-K # suppresses keyword expansion when updating ktext files on the client | |
-n # previews the operation without altering files | |
-N # previews the operation with additional information about any non-content resolve actions that are scheduled | |
-o # displays the base file name and revision to be used during the merge | |
-t # forces 'p4 resolve' to attempt a textual merge, even for files with non-text (binary) types | |
-v # causes 'p4 resolve' to insert markers for all changes, not just conflicts | |
-c: number@"nu-complete p4 changes pending" # limits 'p4 resolve' to the files in changelist# | |
] | |
# Revert open files and restore originals to workspace | |
export extern "p4 revert" [ | |
...file: string # the files to be reverted | |
-a # reverts only files that are open for edit, add, or integrate and are unchanged or missing | |
-n # displays a preview of the operation | |
-k # marks the file as reverted in server metadata without altering files in the client workspace | |
-K # suppresses keyword expansion when updating ktext files on the client | |
-w # causes files that are open for add to be deleted from the workspace when they are reverted | |
-c: number@"nu-complete p4 changes pending" # reverts files that are open in the specified changelist | |
--remote: string # useful for DVCS configurations in which files of type +l are in use | |
] | |
# Submit open files to the depot | |
export extern "p4 submit" [ | |
...file: string # if specified, only files in the default changelist that match the pattern are submitted | |
-c: number@"nu-complete p4 changes pending" # submits the specified pending changelist instead of the default changelist | |
-e: number # submits a shelved changelist without transferring files or modifying the workspace | |
-d: string # passes a description into the specified changelist rather than displaying the changelist dialog for manual editing | |
--noretransfer: number # override the submit.noretransfer configurable | |
] | |
# Synchronize the client with its view of the depot | |
export extern "p4 sync" [ | |
...file: string # if file arguments are given, sync limits its operation to those files | |
-f # forces resynchronization even if the client already has the file, and overwriting any writable files | |
-n # previews the operation without updating the workspace | |
-N # previews the operation without updating the workspace, but reports only a summary of the work the sync would do | |
-k # updates server metadata without syncing files | |
-K # suppresses keyword expansion | |
-p # populates the client workspace, but does not update the server to reflect those updates | |
-q # suppresses normal output messages | |
-r # allows open files which are mapped to new locations in the depot to be reopened in the new location | |
-s # adds a safety check before sending content to the client workspace | |
-m # limits sync to the first 'max' number of files | |
-E # verifies that any changelists specified in the revRange are existing, submitted changes before performing the sync | |
--parallel # specifies options for parallel file transfer | |
--use-stream-change: number # specifies options for syncing stream clients using the stream view at or before change N | |
] | |
# Synonym for 'sync -s' | |
export extern "p4 update" [ | |
] | |
# List Perforce users | |
export extern "p4 users" [ | |
...user: string # list all users that match the user argument | |
-m: number # limits output to the first 'max' number of users | |
-a # includes service and operator users in the output | |
-l # includes additional information in the output | |
-r # only users who have used a replica are reported | |
-c # only the user information from the central server is reported | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment