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
+74 -21
Diff #1
+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
+46 -18
src/open-profile.tsx
··· 17 17 import os from "node:os"; 18 18 import { useEffect, useState } from "react"; 19 19 import { Preferences } from "./types/preferences"; 20 - import { Profile, WindowsTerminalSettings, Folder, FolderEntry } from "./types/windows-terminal"; 20 + import { Profile, WindowsTerminalSettings, Folder } from "./types/windows-terminal"; 21 21 import { getAllProfilePreferences, getProfilePreferences } from "./utils/profile-preferences"; 22 22 import React from "react"; 23 23 ··· 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 + accessories={ 188 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 189 + ? [ 190 + { 191 + tag: { 192 + value: 193 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 194 + .alias, 195 + }, 196 + }, 197 + ] 198 + : undefined 199 + } 200 + actions={ 201 + <Actions 202 + profile={props.profiles.filter((profile) => profile.guid === item.profile)[0]} 203 + alias={ 204 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 205 + ? getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 206 + .alias 207 + : "" 208 + } 209 + /> 210 + } 178 211 icon={ 179 212 props.profiles.filter((profile) => profile.guid === item.profile)[0].source === 180 213 "Windows.Terminal.SSH" ··· 205 238 : props.profiles.filter((profile) => profile.guid === item.profile)[0].guid === 206 239 "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}" 207 240 ? ["cmd"] 208 - : [] 241 + : [ 242 + getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 243 + ? getAliases[props.profiles.filter((profile) => profile.guid === item.profile)[0].guid] 244 + .alias 245 + : "", 246 + ] 209 247 } 210 248 /> 211 249 ); ··· 361 399 ? ["pwsh", "ps", "posh", getAliases[item.guid] ? getAliases[item.guid].alias : ""] 362 400 : item.guid === "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}" 363 401 ? ["cmd", getAliases[item.guid] ? getAliases[item.guid].alias : ""] 364 - : [ 365 - getAliases[item.guid] ? getAliases[item.guid].alias : "" 366 - ] 402 + : [getAliases[item.guid] ? getAliases[item.guid].alias : ""] 367 403 } 368 404 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 - } 405 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 372 406 /> 373 407 ))} 374 408 </List.Section> ··· 385 419 title={item.name} 386 420 keywords={[getAliases[item.guid] ? getAliases[item.guid].alias : ""]} 387 421 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 - } 422 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 391 423 /> 392 424 ))} 393 425 </List.Section> ··· 405 437 title={item.name} 406 438 keywords={[getAliases[item.guid] ? getAliases[item.guid].alias : ""]} 407 439 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 - } 440 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 411 441 /> 412 442 ))} 413 443 </List.Section> ··· 430 460 title={item.name} 431 461 keywords={[getAliases[item.guid] ? getAliases[item.guid].alias : ""]} 432 462 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 - } 463 + actions={<Actions profile={item} alias={getAliases[item.guid] ? getAliases[item.guid].alias : ""} />} 436 464 /> 437 465 ))} 438 466 </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