Add setup for fish

Fixes #131
This commit is contained in:
Max Goedjen 2020-09-18 13:19:46 -07:00
parent 0f6f7c6503
commit d2bb2aa2f6
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8

View File

@ -15,9 +15,10 @@ struct SetupView: View {
} }
SetupStepView(text: "Add this line to your shell config (.bashrc or .zshrc) telling SSH to talk to SecretAgent when it wants to authenticate. Drag this into your config file.", SetupStepView(text: "Add this line to your shell config (.bashrc or .zshrc) telling SSH to talk to SecretAgent when it wants to authenticate. Drag this into your config file.",
index: 2, index: 2,
nestedView: SetupStepCommandView(text: Constants.socketPrompt), nestedView: SetupStepCommandView(instructions: Constants.socketPrompts, selectedShellInstruction: Constants.socketPrompts.first!),
actionText: "Added") { actionText: "Added") {
markAsDone() markAsDone()
}
SetupStepView<Spacer>(text: "Secretive will periodically check with GitHub to see if there's a new release. If you see any network requests to GitHub, that's why.", SetupStepView<Spacer>(text: "Secretive will periodically check with GitHub to see if there's a new release. If you see any network requests to GitHub, that's why.",
index: 3, index: 3,
nestedView: nil, nestedView: nil,
@ -86,11 +87,15 @@ struct SetupStepView<NestedViewType: View>: View {
struct SetupStepCommandView: View { struct SetupStepCommandView: View {
let text: String let instructions: [ShellConfigInstruction]
@State var selectedShellInstruction: ShellConfigInstruction
var body: some View { var body: some View {
TabView(selection: $selectedShellInstruction) {
ForEach(instructions) { instruction in
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(text) Text(instruction.text)
.lineLimit(nil) .lineLimit(nil)
.font(.system(.caption, design: .monospaced)) .font(.system(.caption, design: .monospaced))
.multilineTextAlignment(.leading) .multilineTextAlignment(.leading)
@ -101,18 +106,21 @@ struct SetupStepCommandView: View {
Text("Copy") Text("Copy")
} }
} }
}.tabItem {
Text(instruction.shell)
} }
.tag(instruction)
.padding() .padding()
.background(Color(white: 0, opacity: 0.10)) }
.cornerRadius(10) }
.onDrag { .onDrag {
NSItemProvider(item: NSData(data: text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String) return NSItemProvider(item: NSData(data: selectedShellInstruction.text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
} }
} }
func copy() { func copy() {
NSPasteboard.general.declareTypes([.string], owner: nil) NSPasteboard.general.declareTypes([.string], owner: nil)
NSPasteboard.general.setString(text, forType: .string) NSPasteboard.general.setString(selectedShellInstruction.text, forType: .string)
} }
} }
@ -133,7 +141,22 @@ extension SetupView {
enum Constants { enum Constants {
static let socketPath = (NSHomeDirectory().replacingOccurrences(of: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String static let socketPath = (NSHomeDirectory().replacingOccurrences(of: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String
static let socketPrompt = "export SSH_AUTH_SOCK=\(socketPath)" static let socketPrompts: [ShellConfigInstruction] = [
ShellConfigInstruction(shell: "zsh", text: "export SSH_AUTH_SOCK=\(socketPath)"),
ShellConfigInstruction(shell: "bash", text: "export SSH_AUTH_SOCK=\(socketPath)"),
ShellConfigInstruction(shell: "fish", text: "set -x SSH_AUTH_SOCK=\(socketPath)"),
]
}
}
struct ShellConfigInstruction: Identifiable, Hashable {
var shell: String
var text: String
var id: String {
shell
} }
} }