launch and manage windows terminal instances with raycast
raycast raycast-extension

implement aliases #2

closed opened by woof.monster targeting main from feature/alias

an attempt to add support for profile aliases, very work in progress and has a lot of issues.

(these do not have any effect in the actual windows terminal or show them in root search) (supersedes #1)

Labels
new-feature
branch

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:fhg4ndnjwmxfkarwaqml7kyo/sh.tangled.repo.pull/3mdlf2xq7mt22
+89 -22
Diff #3
+24
src/utils/profile-preferences.ts
··· 1 + import { LocalStorage } from "@raycast/api"; 2 + 3 + export async function getProfilePreferences(guid: string): Promise<{ alias: string }> { 4 + const profile = await LocalStorage.getItem<string>(guid); 5 + 6 + if (profile === undefined) { 7 + return { 8 + alias: "", 9 + }; 10 + } else { 11 + return JSON.parse(profile); 12 + } 13 + } 14 + 15 + export async function getAllProfilePreferences(): Promise<{ [key: string]: { alias: string } }> { 16 + const profiles = await LocalStorage.allItems<{ [key: string]: string }>(); 17 + const reconstructedProfiles: { [key: string]: { alias: string } } = {}; 18 + 19 + for (const i in profiles) { 20 + reconstructedProfiles[i] = JSON.parse(profiles[i]); 21 + } 22 + 23 + return reconstructedProfiles; 24 + }
+4 -3
CHANGELOG.md
··· 3 3 ## [Features and Fixes] - {PR_MERGE_DATE} 4 4 5 5 - Add ability to filter profiles by source 6 - - [REGRESSION] Selecting a specific source, then selecting all sources does 7 - not make the selection jump to the top 8 - - [NOTIMPLEMENTED] Add ability to create aliases of profiles 6 + - [BUG] Selecting a specific source, then selecting all sources does 7 + not make the selection jump to the top 8 + - Add ability to create aliases of profiles 9 9 - Add support for new tab menu folders (including nested) 10 10 - Add support for profiles generated by Visual Studio 11 + - Add better handling for profiles that run elevated by default
+61 -19
src/open-profile.tsx
··· 162 162 } 163 163 164 164 function FolderView(props: { folder: Folder; profiles: Profile[] }) { 165 + const [getAliases, setAliases] = useState<{ [key: string]: { alias: string } }>({}); 166 + 167 + useEffect(() => { 168 + async function load() { 169 + const profiles = await getAllProfilePreferences(); 170 + setAliases(profiles); 171 + } 172 + load(); 173 + }, []); 174 + 165 175 return ( 166 176 <List searchBarPlaceholder={`Search in ${props.folder.name}...`}> 167 177 <List.Section title={props.folder.name}> ··· 174 184 <List.Item 175 185 key={item.profile} 176 186 title={props.profiles.filter((profile) => profile.guid === item.profile)[0].name} 177 - actions={<Actions profile={props.profiles.filter((profile) => profile.guid === item.profile)[0]} />} 187 + actions={ 188 + <Actions 189 + profile={props.profiles.filter((profile) => profile.guid === item.profile)[0]} 190 + alias={ 191 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 192 + ? getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 193 + .alias 194 + : "" 195 + } 196 + /> 197 + } 178 198 icon={ 179 199 props.profiles.filter((profile) => profile.guid === item.profile)[0].source === 180 200 "Windows.Terminal.SSH" ··· 201 221 "{574e775e-4f2a-5b96-ac1e-a2962a402336}" || // Windows PowerShell 7.0+ 202 222 props.profiles.filter((profile) => profile.guid === item.profile)[0].source === 203 223 "Windows.Terminal.PowershellCore" // Windows Powershell 7.0+ (source for better handling) 204 - ? ["pwsh", "ps", "posh"] 224 + ? [ 225 + "pwsh", 226 + "ps", 227 + "posh", 228 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 229 + ? getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 230 + .alias 231 + : "", 232 + ] 205 233 : props.profiles.filter((profile) => profile.guid === item.profile)[0].guid === 206 234 "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}" 207 - ? ["cmd"] 208 - : [] 235 + ? [ 236 + "cmd", 237 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 238 + ? getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 239 + .alias 240 + : "", 241 + ] 242 + : [ 243 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 244 + ? getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 245 + .alias 246 + : "", 247 + ] 248 + } 249 + accessories={ 250 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 251 + ? [ 252 + { 253 + tag: { 254 + value: 255 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 256 + .alias, 257 + }, 258 + }, 259 + ] 260 + : undefined 209 261 } 210 262 /> 211 263 ); ··· 361 413 ? ["pwsh", "ps", "posh", getAliases[item.guid] ? getAliases[item.guid].alias : ""] 362 414 : item.guid === "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}" 363 415 ? ["cmd", getAliases[item.guid] ? getAliases[item.guid].alias : ""] 364 - : [ 365 - getAliases[item.guid] ? getAliases[item.guid].alias : "" 366 - ] 416 + : [getAliases[item.guid] ? getAliases[item.guid].alias : ""] 367 417 } 368 418 accessories={getAliases[item.guid] ? [{ tag: { value: getAliases[item.guid].alias } }] : undefined} 369 - actions={ 370 - <Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} /> 371 - } 419 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 372 420 /> 373 421 ))} 374 422 </List.Section> ··· 385 433 title={item.name} 386 434 keywords={[getAliases[item.guid] ? getAliases[item.guid].alias : ""]} 387 435 accessories={getAliases[item.guid] ? [{ tag: { value: getAliases[item.guid].alias } }] : undefined} 388 - actions={ 389 - <Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} /> 390 - } 436 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 391 437 /> 392 438 ))} 393 439 </List.Section> ··· 405 451 title={item.name} 406 452 keywords={[getAliases[item.guid] ? getAliases[item.guid].alias : ""]} 407 453 accessories={getAliases[item.guid] ? [{ tag: { value: getAliases[item.guid].alias } }] : undefined} 408 - actions={ 409 - <Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} /> 410 - } 454 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 411 455 /> 412 456 ))} 413 457 </List.Section> ··· 430 474 title={item.name} 431 475 keywords={[getAliases[item.guid] ? getAliases[item.guid].alias : ""]} 432 476 accessories={getAliases[item.guid] ? [{ tag: { value: getAliases[item.guid].alias } }] : undefined} 433 - actions={ 434 - <Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} /> 435 - } 477 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 436 478 /> 437 479 ))} 438 480 </List.Section>

History

4 rounds 2 comments
sign up or login to add to the discussion
7 commits
expand
aliases proof of concept
add better handling of built-in keywords for powershell core
resolve type errors in folder view
added better handling for azure cloud shell profiles
change note from regression to bug in changelog
merge from main branch
add support for aliases in folders
expand 1 comment

development on aliases has been abandoned due to extreme complexity and high implications, focus is now shifting to adding more shorthands as keywords to more profiles instead

closed without merging
6 commits
expand
aliases proof of concept
add better handling of built-in keywords for powershell core
resolve type errors in folder view
added better handling for azure cloud shell profiles
change note from regression to bug in changelog
merge from main branch
expand 0 comments
7 commits
expand
aliases proof of concept
resolve merge conflicts
resolve type errors in folder view
added better handling for azure cloud shell profiles
change note from regression to bug in changelog
merge from main branch
add support for aliases in folders
expand 0 comments
1 commit
expand
aliases proof of concept
expand 1 comment

current issues

  • raycast rerenders the alias editor view every time the text entry value changes via user input
  • aliases require relaunching to take effect
  • using the escape key to exit the view is sometimes blocked by the text entry
  • presetting the text entry value results in more issues somehow