2016.1 Command Line Roundup
Today's post is for those of us who still find ourselves spending a good chunk of our time at the shell prompt. Here are some of the minor features we've gained in 2016.1 to address common command line annoyances:
The --me option
#1237288 (Bug #79804) ** The new option '--me' can be used with 'p4 changes' and 'p4 clients/labels/branches' as a shorthand for '-u $P4USER'.
This simple little feature came out of the observation that we spend a lot of time typing "-u my_name", and if you're writing a script that wants to do something like it, you're probably spending even more time getting the script to figure out what "my_name" should be. Now it's just "--me"!
#1243015 (Bug #79913) * ** The p4 command line, run interactively, will now prompt for login if a command that requires authentication is run when the user is not authenticated. If the login is successful, the original command continues.
If like most users you have a 12-hour login timeout, you're probably very familiar with this sequence of events:
% p4 sync Your session has expired, please login again. % p4 login Enter password: User sam logged in. % p4 sync File(s) up-to-date.
Now when you try to run a command with an expired ticket, it looks more like this:
% p4 sync Your session has expired, please login again. Attempting login for user 'sam' against server 'perforce:1666' Enter password: User sam logged in. File(s) up-to-date.
#1243887 (Bug #63964) ** 'p4 annotate' now features a '-T' flag to align the leading part of each line of output to a tab stop. See 'p4 help annotate'.
The "p4 annotate" command is wonderfully useful for tracking down the history of a particular piece of content, but trying to read the version information when it's mixed into the content can get a little annoying when all those pieces of information don't line up nicely:
1334640: bpendleton 2016/01/26 Version 2016.1 3363: seiwald 1997/06/04 3363: seiwald 1997/06/04 Introduction 3363: seiwald 1997/06/04 1209955: smisra 2015/07/28 This document lists all user-visible changes to the Helix 1209955: smisra 2015/07/28 Versioning Engine (P4D) and command line client (P4) between
With the new -T flag, the output is all lined up into neat columns:
1334640: bpendleton 2016/01/26 Version 2016.1 0003363: seiwald 1997/06/04 0003363: seiwald 1997/06/04 Introduction 0003363: seiwald 1997/06/04 1209955: smisra 2015/07/28 This document lists all user-visible changes to the Helix 1209955: smisra 2015/07/28 Versioning Engine (P4D) and command line client (P4) between
If tabstops of 8 aren't your thing, you can use the "--tab=N" form to specify your own.
Bonus undoc feature: p4 --field
This one is in "p4 help undoc", right under the "-F" flag (which is also really cool):
p4 --field Field=replacement_text p4 --field Field+=extra_text Modify the contents of a spec returned by p4 [specname] -o. The modified spec can be piped directly to another command that expects a formatted spec, e.g. p4 [specname] -i.
The usefulness of this won't be apparent unless you've ever had to write something like this:
% p4 change -o | sed -e "s/<enter description here>/foo/" | p4 change -i
If you happen to be in a shell that doesn't have "sed" installed by default, or if you're trying to act on an arbitrary field (maybe one that has multiple lines, even), this gets much more difficult. The various APIs all have nice methods to access the different fields of a spec individually, but if you're trying to just throw a couple of shell commands together, manipulating specs has historically been more difficult that it seems like it should have to be.
With the new --field option you can now do things like:
% p4 --field Description=foo change -o | p4 change -i % p4 --field "View=//depot/dev/me/... //myclient/..." client -o | p4 client -i % p4 --field "Paths+=share dir2/..." stream -o | p4 stream -i
Note that this is a client-side global option, so it works for any command that returns a spec, for any field, and it does not require a new server. It's a fairly simple tool and there are still a few tasks related to editing specs that you'll need to go into a full-fledged scripting language for, but much like the -F option, in the short time I've had this available to me I've been amazed at how much time it's saved me.
But wait, there's more!
This isn't all we've got in 2016.1 for command line users -- keep an eye out for an upcoming post in which we'll be talking about aliases!