Title: Introduce a cmdlet for manipulation of list strings · Issue #7975 · PowerShell/PowerShell · GitHub
Open Graph Title: Introduce a cmdlet for manipulation of list strings · Issue #7975 · PowerShell/PowerShell
X Title: Introduce a cmdlet for manipulation of list strings · Issue #7975 · PowerShell/PowerShell
Description: Note: Should this suggestion gain traction, an RFC is presumably needed. By list string I mean a single string composed of items (tokens) separated by a separator, such as you would find in $env:PATH, which contains a list of directories...
Open Graph Description: Note: Should this suggestion gain traction, an RFC is presumably needed. By list string I mean a single string composed of items (tokens) separated by a separator, such as you would find in $env:PA...
X Description: Note: Should this suggestion gain traction, an RFC is presumably needed. By list string I mean a single string composed of items (tokens) separated by a separator, such as you would find in $env:PA...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/7975
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Introduce a cmdlet for manipulation of list strings","articleBody":"Note:\r\n* Should this suggestion gain traction, an RFC is presumably needed.\r\n* By _list string_ I mean a single string composed of items (tokens) separated by a separator, such as you would find in ` $env:PATH`, which contains a list of directories.\r\n* This suggestion is in part motivated by wanting a platform-independent mechanism for manipulating environment variables such as `$env:PATH` safely and conveniently - see #5340 and \r\nhttps://github.com/PowerShell/PowerShell-RFC/pull/92\r\n\r\nManipulating such lists with text parsing is cumbersome, error-prone, and sometimes requires platform-specific separators, so a dedicated cmdlet, say `Update-ListString` (name negotiable) could ease the burden, by offering the following operations, with support for adding/removing _arrays_ of items:\r\n\r\n* adding items:\r\n * prepend (`-Prepend`)\r\n * append (`-Append`)\r\n * insert before or after a given item (`-InsertBefore` / `-InsertAfter`) - same as `-Append`, if the item doesn't exist\r\n* replacing items:\r\n * by name (item string) of an existing item (`-Replace`) - same as `-Append`, if the item doesn't exist.\r\n* removing items:\r\n * by name (item string) (`-Remove`)\r\n * removing duplicate items on request (`-RemoveDuplicate`), keeping only the first occurrence\r\n * remove empty items (duplicate separators) on request (`-RemoveEmpty`)\r\n\r\nOperations should be idempotent by default (desired-state logic):\r\n * on adding, quietly do nothing if the item(s) already exist\r\n * on removing, ignore the case where item(s) don't exist\r\n\r\nWith `-Force`, _add_ operations should enforce the specified position - `-Prepend`, `-Append`, `-InsertAt`, `-InsertBefore/After` - by moving a preexisting item accordingly.\r\n\r\nSeparators can either be specified:\r\n\r\n* freely, as a regex (as you would pass to `-split`), with `-Separator` \r\n* or via switch `-AsDirList` (name negotiable), in which case `[IO.Path]::PathSeparator` is used, representing the platform-appropriate separator used to separate entries in `$env:PATH` (and similar variables such as `$env:CLASSPATH`).\r\n\r\nOpen questions:\r\n\r\n* Is it necessary to also support _by-index_ operations (`-InsertAt`, `-RemoveAt`, `-ReplaceAt`)? Conceivably, this could be added later.\r\n* How should _escaping_ of separators embedded in items be handled? The simplest case would be to simply _disallow_ embedded separators in items (assume that existing items don't have embedded separators, and report an error on trying to set items containing them). Conceivably, support for escaping could be added later via an `-EscapeChar` parameter.\r\n\r\nExamples:\r\n\r\n```powershell\r\n# WISHFUL THINKING\r\n\r\nPS> Update-ListString -Separator ';' 'a;b;c' -Append 'd', 'e'\r\na;b;c;d;e\r\n\r\nPS> Update-ListString -Separator ';' 'a;b;c' -Prepend 'd'\r\nd;a;b;c\r\n\r\nPS> Update-ListString -Separator ';' 'a;b;c;d' -Remove 'd', 'b'\r\na;c\r\n\r\nPS> Update-ListString -Separator ';' 'a;;c' -RemoveEmpty\r\na;c\r\n\r\nPS> Update-ListString -Separator ';' 'a;b;a;c' -RemoveDuplicate\r\na;b;c\r\n\r\nPS> Update-ListString -Separator ';' 'a;b;c' -Replace 'b', 'd'\r\na;d;c\r\n\r\n# No-op, if entry already present\r\nPS> Update-ListString -Separator ';' 'a;b;c' -Append 'b'\r\na;b;c\r\n\r\n# Enforce specified position\r\nPS> Update-ListString -Separator ';' 'a;b;c' -Append 'b' -Force\r\na;c;b\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\nWritten as of:\r\n\r\n```powershell\r\nPowerShell Core 6.1.0\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-10-08T20:01:59Z","url":"https://github.com/PowerShell/PowerShell/issues/7975"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7c12adaa-a34b-6f45-ebd3-bbfe6e3024f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C706:2F6606:2194F66:2EED86E:6AFD31BD |
| html-safe-nonce | 81d78ad8d2d047f2455e6ee3afccd74948f3f7ffdc37c112634f2f09c768c5cb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzA2OjJGNjYwNjoyMTk0RjY2OjJFRUQ4NkU6NkFGRDMxQkQiLCJ2aXNpdG9yX2lkIjoiNjE2NzYwMDYxNjgzNTk4NTg1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 63cda4e1cdb168b450b7e463c58637f19c35242d56dd410b4df9fc8ce1ef37b7 |
| hovercard-subject-tag | issue:367932914 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/7975/issue_layout |
| twitter:image | https://opengraph.githubassets.com/30ddc7851a052b99d8b0495e095267645518c74a1b10c00c036c998644b6aeed/PowerShell/PowerShell/issues/7975 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/30ddc7851a052b99d8b0495e095267645518c74a1b10c00c036c998644b6aeed/PowerShell/PowerShell/issues/7975 |
| og:image:alt | Note: Should this suggestion gain traction, an RFC is presumably needed. By list string I mean a single string composed of items (tokens) separated by a separator, such as you would find in $env:PA... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 941021edf0c2ec58298f4a2c8f27ae507d129c92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width