Skip to content

Commit

Permalink
SSH: added option to use custom SSH keys
Browse files Browse the repository at this point in the history
Gopls LSP: enable semantic tokens colouring by default
  • Loading branch information
eranif committed Jul 16, 2024
1 parent f976b92 commit e31f52a
Show file tree
Hide file tree
Showing 18 changed files with 590 additions and 272 deletions.
27 changes: 19 additions & 8 deletions CodeLite/ssh/clSSHAgent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "clSSHAgent.hpp"

#include "AsyncProcess/asyncprocess.h"
#include "StringUtils.h"
#include "file_logger.h"
#include "fileutils.h"
#include "procutils.h"
Expand All @@ -11,21 +12,25 @@
#ifndef __WXMSW__
static wxString& AddQuotesIfNeeded(wxString& str)
{
if(str.Contains(" ")) {
if (str.Contains(" ")) {
str.Prepend("\"").Append("\"");
}
return str;
}
#endif

clSSHAgent::clSSHAgent() { Start(); }
clSSHAgent::clSSHAgent(const wxArrayString& files)
: m_files(files)
{
Start();
}

clSSHAgent::~clSSHAgent() { Stop(); }

void clSSHAgent::Start()
{
wxFileName sshAgent;
if(!FileUtils::FindExe("ssh-agent", sshAgent)) {
if (!FileUtils::FindExe("ssh-agent", sshAgent)) {
clDEBUG() << "Could not find ssh-agent executable";
return;
}
Expand All @@ -34,11 +39,11 @@ void clSSHAgent::Start()
// Check if an instance of ssh-agent is already running
#ifdef __WXMSW__
PidVec_t P = ProcUtils::PS("ssh-agent");
if(P.empty()) {
if (P.empty()) {
clDEBUG() << "Could not find a running instance of ssh-agent, starting one...";
m_process = ::CreateAsyncProcess(nullptr, sshAgent.GetFullPath(),
IProcessCreateWithHiddenConsole | IProcessCreateDefault);
if(m_process) {
if (m_process) {
clDEBUG() << "Started" << sshAgent << "with process ID:" << m_process->GetPid() << clEndl;
} else {
clWARNING() << "Failed to start" << sshAgent << "ssh-agent daemon" << clEndl;
Expand All @@ -59,7 +64,7 @@ void clSSHAgent::Start()
command << " -D -a " << socketPath;

m_process = ::CreateAsyncProcess(nullptr, command);
if(!m_process) {
if (!m_process) {
clWARNING() << "Failed to launch" << command << clEndl;
} else {
clDEBUG() << "Starting ssh-agent:" << command << ". pid:" << m_process->GetPid();
Expand All @@ -79,12 +84,18 @@ void clSSHAgent::Start()

// Execute ssh-add
sshAgent.SetFullName("ssh-add");
ProcUtils::SafeExecuteCommand(sshAgent.GetFullPath());
wxString ssh_add_command = StringUtils::WrapWithDoubleQuotes(sshAgent.GetFullPath());

// Pass the key files to load
for (const auto& keyfile : m_files) {
ssh_add_command << " " << StringUtils::WrapWithDoubleQuotes(keyfile);
}
ProcUtils::SafeExecuteCommand(ssh_add_command);
}

void clSSHAgent::Stop()
{
if(m_process) {
if (m_process) {
m_process->Terminate();
wxDELETE(m_process);
}
Expand Down
5 changes: 4 additions & 1 deletion CodeLite/ssh/clSSHAgent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
#define CLSSHAGENT_HPP

#include "codelite_exports.h"

#include <memory>
#include <wx/arrstr.h>
#include <wx/sharedptr.h>

class IProcess;
class WXDLLIMPEXP_CL clSSHAgent
{
private:
IProcess* m_process = nullptr;
wxArrayString m_files;

protected:
void Start();
Expand All @@ -19,7 +22,7 @@ class WXDLLIMPEXP_CL clSSHAgent
typedef std::shared_ptr<clSSHAgent> Ptr_t;

public:
clSSHAgent();
clSSHAgent(const wxArrayString& files = {});
virtual ~clSSHAgent();
};

Expand Down
Loading

0 comments on commit e31f52a

Please sign in to comment.