dotfiles

Cross platform dotfiles for linux, mac and windows
git clone git@getsh.org:dotfiles.git
Log | Files | Refs

commit 6128ecc7ed791bc061f3912d077152aa970c4a8b
parent 5d25f60e4bfdd3a4c8a3174fba607fa3ee24b9ca
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date:   Tue, 20 Aug 2024 20:46:26 +0530

Optimize cmd setup

1. Move Environment variables to setup.cmd to be less dependent on
profile.cmd. This also avoids setting up the variables everytime.
Another advantager is that gvim works without XDG_* path errors!

2. Remove useless(AFAIK) cd %USERPROFILE% in profile.cmd.

3. Remove aliases.cmd and move all dosey to profile.cmd

Diffstat:
D.config/cmd/aliases.cmd | 14--------------
M.config/cmd/setup.cmd | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
M.config/profile.cmd | 30+++++++++++-------------------
3 files changed, 65 insertions(+), 47 deletions(-)

diff --git a/.config/cmd/aliases.cmd b/.config/cmd/aliases.cmd @@ -1,14 +0,0 @@ -doskey n=cd $* -doskey g=git $* -doskey e=%EDITOR% $* -doskey l=lfcd.cmd -doskey ls=dir /B $* -doskey cp=copy $* -doskey m=make $* -doskey mv=move $* -doskey pwd=cd -doskey rm=del $* -doskey clear=cls -doskey lynx=lynx -cfg %USERPROFILE%\.config\lynx\lynx.cfg $* -doskey cat=type $* -doskey hb=sh %USERPROFILE%\.local\bin\sh\hb $* diff --git a/.config/cmd/setup.cmd b/.config/cmd/setup.cmd @@ -1,7 +1,28 @@ @echo on - rem TODO Make this work for Administrator accounts +goto :main + +:set_var + set _tail=%* + call set _tail=%%_tail:*%1 =%% + echo Setting "%~1" to "%_tail%" + setx %~1 "%_tail%" + set %~1=%_tail% +goto :eof + +:add_path + for /f "tokens=2* skip=2" %%i in ('reg query HKCU\Environment /v PATH') do ( + echo %%j | find /i "%~1" || call :set_var PATH %%j;%~1 + ) +goto :eof + +:update_shim <shim_file> <path> <args> + echo path = "%~2"> %~1 + echo args = %~3>> %~1 +goto :eof + +:main where scoop >nul 2>&1 if not %errorlevel% equ 0 ( rem Run this in powershell, before @@ -10,29 +31,48 @@ rem Run this in powershell, before echo powershell -Command "Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')" rem Install only the absolute essentials echo scoop config shim 71 - echo scoop install 7zip clink dos2unix grep gpg lf make mingit mpv sed sudo unzip vim echo scoop reset -a + echo scoop install 7zip clink dos2unix grep gpg lf make mingit mpv sed sudo unzip vim exit 1 ) -@call %~dp0\..\profile.cmd +@call %~dp0\..\profile.cmd %1 + +call :set_var XDG_ROOT %USERPROFILE% +if NOT "%1" == "" call :set_var XDG_ROOT "" + +call :add_path "C:\bin" +call :set_var XDG_ROOT %USERPROFILE% +call :set_var XDG_CONFIG_HOME %XDG_ROOT%\.config +call :set_var XDG_DATA_HOME %XDG_ROOT%\.local\share +call :set_var XDG_CACHE_HOME %XDG_ROOT%\.cache +call :set_var SCOOP %XDG_ROOT%\scoop + +call :set_var VISUAL vim +call :set_var EDITOR %VISUAL% + +call :set_var GNUPGHOME %XDG_DATA_HOME%\gnupg +call :set_var GPGHOME %XDG_DATA_HOME%\gnupg +call :set_var PASSWORD_STORE_DIR %XDG_DATA_HOME%\pass +call :set_var PASS_BASE_DIR %XDG_DATA_HOME%\pass + +call :set_var FUZZER fzf + +call :add_path %USERPROFILE%\.local\bin\cmd rem Apply config patches rem TODO Use mklink instead of xcopy, it will prevent overriding changed files in the destination dir. xcopy /Y %USERPROFILE%\.config\cmd\patch %USERPROFILE%\ /S /E -rem IF NOT EXIST %USERPROFILE%\.config\vim\vimrc mklink %USERPROFILE%\_vimrc %USERPROFILE%\.config\vim\vimrc - -if "%SCOOP%" == "" ( - echo "SCOOP variable not set, defaulting to %USERPROFILE%\scoop" - set SCOOP=%USERPROFILE%\scoop -) - mkdir %SYSTEMDRIVE%\bin -copy %SCOOP%\apps\busybox\current\busybox.exe %SYSTEMDRIVE%\bin -copy %SCOOP%\shims\sh.exe %SYSTEMDRIVE%\bin -echo path = "C:\bin\busybox.exe" > C:\bin\sh.shim -echo args = sh -l >> C:\bin\sh.shim +if EXIST "%SCOOP%\apps\busybox\current\busybox.exe" ( + copy "%SCOOP%\apps\busybox\current\busybox.exe" %SYSTEMDRIVE%\bin + copy "%SCOOP%\apps\scoop\current\supporting\shims\71\shim.exe" %SYSTEMDRIVE%\bin\sh.exe + call :update_shim C:\bin\sh.shim "C:\bin\busybox.exe" "sh -l" +) +if EXIST "%SCOOP%\apps\lynx\current\lynx.exe" ( + call :update_shim "%SCOOP%\shims\lynx.shim" "%SCOOP%\apps\lynx\current\lynx.exe" "-cfg %XDG_CONFIG_HOME%\lynx\lynx.cfg" +) rem TODO Report this in scoop and remove this line del %SCOOP%\apps\gpg\current\bin\gpgconf.ctl diff --git a/.config/profile.cmd b/.config/profile.cmd @@ -1,23 +1,15 @@ @echo off -cd %USERPROFILE% +doskey n=cd $* +doskey g=git $* +doskey e=%EDITOR% $* +doskey l=lfcd.cmd +doskey ls=dir /B $* +doskey m=make $* +doskey pwd=cd +doskey rm=del $* +doskey clear=cls +doskey cat=type $* +doskey hb=sh %USERPROFILE%\.local\bin\sh\hb $* -set XDG_ROOT=%1 -if "%XDG_ROOT%" == "" set XDG_ROOT=%USERPROFILE% -set XDG_CONFIG_HOME=%XDG_ROOT%\.config -set XDG_DATA_HOME=%XDG_ROOT%\.local\share -set XDG_CACHE_HOME=%XDG_ROOT%\.cache -set VISUAL=vim -set EDITOR=%VISUAL% - -set GNUPGHOME=%XDG_DATA_HOME%/gnupg -set GPGHOME=%XDG_DATA_HOME%/gnupg -set PASSWORD_STORE_DIR=%XDG_DATA_HOME%/pass -set PASS_BASE_DIR=%XDG_DATA_HOME%/pass - -set FUZZER=fzf - -set PATH=%PATH%;%USERPROFILE%\.local\bin\cmd;%USERPROFILE%\work\spm - -@call %XDG_CONFIG_HOME%\cmd\aliases.cmd if exist "%XDG_CONFIG_HOME%\cmd\userenv.cmd" @call %XDG_CONFIG_HOME%\cmd\userenv.cmd