Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
MartiUK committed May 17, 2015
2 parents f5ce49b + 2383777 commit 3966ed9
Show file tree
Hide file tree
Showing 24 changed files with 2,824 additions and 115 deletions.
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

## Those files should be taken from their repositary

vendor/*
!vendor/*.md
!vendor/*.bat
!vendor/*.json
vendor/*/*
!vendor/*
!vendor/psmodules/PsGet

config/.history
Thumbs.db
*.exe
build/
Version v*
Version v*
Binary file removed Cmder.exe
Binary file not shown.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The main advantage of Cmder is portability. It is designed to be totally self-co

1. Download the latest release
1. Extract
1. (optional) Place files into `bin` folder, it will be injected into your PATH.
1. (optional) Place your own executable files into the `bin` folder to be injected into your PATH.
1. Run cmder

*(There will be a version with installer)*
Expand Down Expand Up @@ -60,6 +60,12 @@ For example there is one defined for you `alias e.=explorer .`

All aliases will be saved in `/config/aliases` file

### SSH Agent

To start SSH agent simply call `agent`, which is in the `bin` folder.

If you want to run SSH agent on startup, uncomment the line in `/vendor/init.bat`so it says `@call "%CMDER_ROOT%/bin/agent.cmd"`.

## Todo

1. Complete PowerShell compatibility.
Expand All @@ -74,7 +80,7 @@ All software included is bundled with own license

The MIT License (MIT)

Copyright (c) 2013 Samuel Vasko
Copyright (c) 2015 Samuel Vasko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 46 additions & 0 deletions bin/agent.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF

REM Set default sock file
SET SSH_AUTH_SOCK=/tmp/ssh-agent.sock

REM Check socket is available
IF NOT EXIST "%TMP%\ssh-agent.sock" GOTO:RUNAGENT

REM Check if an ssh-agent is running
FOR /f "tokens=*" %%I IN ('ps ^| grep ssh-agent ^| sed "s/^ *\([0-9]\+\) .*/\1/"') DO SET VAR=%%I
IF "%VAR%" == "" GOTO:RUNAGENT

REM Check if socket file is valid
ssh-add -l 1> NUL 2>&1
IF ERRORLEVEL 1 GOTO:RUNAGENT
GOTO:ADDKEYS

:RUNAGENT
REM Remove old socket file
rm -f /tmp/ssh-agent.sock

REM Run ssh-agent and save (last) PID in VAR
SET VAR=
FOR /f "tokens=*" %%J IN ('ssh-agent -a /tmp/ssh-agent.sock') DO FOR /f "tokens=*" %%K IN ('echo %%J ^| grep "SSH_AGENT_PID" ^| sed "s/^SSH_AGENT_PID=\([0-9]\+\); .*/\1/"') DO SET VAR=%%K

:ADDKEYS
SET SSH_AUTH_PID=%VAR%

REM Check if ssh keys are known
SET KEYS=
FOR /f "tokens=*" %%I IN ('DIR /B "%HOME%\.ssh\*_rsa"') DO CALL:CHECKKEY %%I

REM Add missing ssh keys at once
IF NOT "%KEYS%" == "" ssh-add %KEYS%
GOTO:END

REM Functions
REM Check if ssh key has to be added
:CHECKKEY
SET VAR=
FOR /f "tokens=*" %%J IN ('ssh-add -l ^| grep "%1"') DO SET VAR=%%J
IF "%VAR%" == "" SET KEYS='%HOME%\.ssh\%1' %KEYS%
GOTO:EOF

:END
@ECHO ON
43 changes: 38 additions & 5 deletions bin/alias.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
@echo off

set ALIASES=%CMDER_ROOT%\config\aliases

if ["%*"] == [""] echo Use /? for help & echo. & goto :p_show
if ["%1"] == ["/?"] goto:p_help
if ["%2"] == [""] echo Insufficient parameters. & goto:p_help
if ["%1"] == ["/reload"] goto:p_reload
:: /d flag for delete existing alias
if ["%1"] == ["/d"] goto:p_del %*
:: if arg is an existing alias, display it
if ["%2"] == [""] (
doskey /macros | findstr /b %1= && goto:eof
echo Insufficient parameters. & goto:p_help
)

::validate alias
setlocal
for /f "delims== tokens=1" %%G in ("%*") do set _temp2=%%G
Expand All @@ -13,15 +25,36 @@ if not ["%_temp%"] == ["%_temp2%"] (
goto:eof
)

echo %* >> "%CMDER_ROOT%\config\aliases"
doskey /macrofile="%CMDER_ROOT%\config\aliases"
echo Alias created
:: replace already defined alias
findstr /b /v /i "%_temp%=" "%ALIASES%" >> "%ALIASES%.tmp"
echo %* >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
doskey /macrofile="%ALIASES%"
endlocal
goto:eof

:p_del
findstr /b /v /i "%2=" "%ALIASES%" >> "%ALIASES%.tmp"
type "%ALIASES%".tmp > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
doskey /macrofile=%ALIASES%
goto:eof

:p_reload
doskey /macrofile="%ALIASES%"
echo Aliases reloaded
goto:eof

:p_show
type "%ALIASES%" || echo No aliases found at "%ALIASES%"
goto :eof

:p_help
echo.Usage:
echo. alias name=full command
echo. alias [/reload] [/d] [name=full command]
echo. /reload Reload the aliases file
echo. /d Delete an alias (must be followed by the alias name)
echo.
echo. If alias is called with any parameters, it will display the list of existing aliases.
echo. In the command, you can use the following notations:
echo. $* allows the alias to assume all the parameters of the supplied command.
echo. $1-$9 Allows you to seperate parameter by number, much like %%1 in batch.
echo. $T is the command seperator, allowing you to string several commands together into one alias.
Expand Down
Loading

0 comments on commit 3966ed9

Please # to comment.