1iJaCk icon

cmdrc.bat

1iJaCk | PRO | 08/18/16 05:49:22 AM UTC | 0 ⭐ | 189 👁️ | Never ⏰ | []
Batch |

9.47 KB

|

None

|

0 👍

/

0 👎

:: Params Check :::::::::::::::::::::::
%*
::   If called with params,          ::
::   run those first                 ::
::                                   ::
:::::::::::::::::::::::::::::::::::::::
 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   USE AT YOUR OWN RISK - Provided AS IS - no warrenty, no support, no guarntee    ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                                                   ::
::                 Alex V. | [email protected] | 08/31/2016 | Version: 1.0                 ::
::                   https://pastebin.com/raw/fxj75AQ0                               ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
 
:: Default Prompt :::::::::::::::::::::
::   Sets Default Prompt value       ::
::                                       
@set "_cmdrc=$_[$D] [$T$H$H$H] [%username%@%computername%] [$p$+]$_$g$g"
:::::::::::::::::::::::::::::::::::::::
 
 
 
:: Run Check ::::::::::::::::::::::::::
::   If cmdrc has already been run   ::
::   it will not run it again        ::
::     Default 1.  If you want it to pull every time regardless, set to 0.
::
@set /a "_cmdrc_init_counter+=1"
@if "%_cmdrc_init_counter%" gtr "1" goto skip_config_pull
:::::::::::::::::::::::::::::::::::::::
 
 
:: Env Swap :::::::::::::::::::::::::::
::   Making sure that your session   ::
::   is least impacted by _cmdrc     ::
::
@setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
@echo off
 
 
 
:: User behavior changes ::::::::::::::
set "_pause_flag="                      rem Default NOTSET. Pauses before giving completing this script
set "_delay_flag="                      rem Default NOTSET. Pauses before giving completing this script
set "_delay_value="                     rem Default 30.  If it is not set, it will default to 10
set "_cmdrc_title=%username%@%computername%" rem Default Command Prompt - %username%@%computername%.  This is the base title string, other info will be appended
:::::::::::::::::::::::::::::::::::::::
 
 
 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                                           ::
:: Start of Script Functions                                                 ::
::   Run Function with the call command                                      ::
::                                                                           ::
::   Example:                                                                ::
::     call :function_name with params "and params with quotes"              ::
::                                                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end_of_script_functions
 
:install_check
goto :eof
 
:install_me
:: Install Option :::::::::::::::::::::
:: Add Context Menu, if needed:
REM cmd_context_menu.reg:
    REM Windows Registry Editor Version 5.00
    REM 
    REM [HKEY_CLASSES_ROOT\Directory\shell\Open Normal Console here]
    REM @="Open Normal Console here"
    REM 
    REM [HKEY_CLASSES_ROOT\Directory\shell\Open Normal Console here\command]
    REM @="title %1 && color 1a && cd /D %1"
    REM 
    REM 
    REM [HKEY_CLASSES_ROOT\Directory\shell\Open Elevated Console here]
    REM @="Open Elevated Console here"
    REM 
    REM [HKEY_CLASSES_ROOT\Directory\shell\Open Elevated Console here\command]
    REM @="C:\\Windows\\System32\\elevate.exe /K \"title %1 && color 1a && cd /D %1\""
    
    
    
:: reg add "HKEY_CLASSES_ROOT\Directory\shell\Open Elevated Console here" /v "@" /t
:::::::::::::::::::::::::::::::::::::::
goto :eof
 
 
goto :eof
:end_of_script_functions
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                                           ::
:: End of Script Functions                                                   ::
::                                                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
 
 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                                           ::
:: Start of config pull                                                      ::
::   This should only happen once                                            ::
::                                                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
:: Checking if this script has already been run in this console session
::
if not defined _cmdrc_init_counter (
    set /a "_cmdrc_init_counter+=1"
    )
:::::::::::::::::::::::::::::::::::::::
 
 
    
:: Print Bar ::::::::::::::::::::::::::
echo/
echo [=======] [CMDrc] [====================]
 
 
 
:: Get Processor info :::::::::::::::::
::
if defined PROCESSOR_ARCHITEW6432 (
    set "Proc_Mode=%PROCESSOR_ARCHITECTURE%[%PROCESSOR_ARCHITEW6432%]"
) else (
    set "Proc_Mode=%PROCESSOR_ARCHITECTURE%"
)
:::::::::::::::::::::::::::::::::::::::
 
 
 
:: Network cable check ::::::::::::::::
::   Only works in Admin Console     ::
::   
set "_cmdrc_no_network_connection="
if defined _cmdrc_admin (
    netsh interface show interface 2>nul | findstr "Connected" 2>&1>nul || set "_cmdrc_no_network_connection=true"
)
:::::::::::::::::::::::::::::::::::::::
 
 
 
:: Get external IP info :::::::::::::::
::   only if cable is connected      ::
::
set "ip_ex_addr_all="
if not defined _cmdrc_no_network_connection (
    for /f "skip=1 tokens=2 delims=: " %%a in ('call nslookup myip.opendns.com. resolver1.opendns.com ^|findstr /i /C:"Address:"') do (
        set "ip_ex_addr_all=%%a"
    ) 2>&1>nul
)
 
if defined ip_ex_addr_all (
    echo External IP Addresses: 
    rem for /f "delims=," %%i in ('echo %ip_ex_addr_all%') do echo      %%i
    for %%i in (%ip_ex_addr_all%) do echo         %%i
    echo/
)
 
if defined ip_ex_addr_all (
    set "_cmdrc_title=%_cmdrc_title% Ext IPS:[%ip_ex_addr_all: =][%]"
)
:::::::::::::::::::::::::::::::::::::::
 
 
 
:: Get local IP info ::::::::::::::::::
::   Defining first three IPs        ::
::   Defining all local IPs          ::
::
set /a count=0
set "ip_addr="
set "ip_lo_addr_all="
 
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr "IPv4"') do (
    set "/a count+=1"
    set "temp_ip_lo_addr=%%a"
    if "!temp_ip_lo_addr:~0,1!" == " " (
        set "temp_ip_lo_addr=!temp_ip_lo_addr:~1%!"
    )
 
    if "!count!" leq "3" (
        if not defined ip_addr (
            set "ip_addr=!temp_ip_lo_addr!"
            set "ip_lo_addr_all=!temp_ip_lo_addr!"
        ) else (
            set "ip_addr=!ip_addr! !temp_ip_lo_addr!"
            set "ip_lo_addr_all=!ip_lo_addr_all! !temp_ip_lo_addr!"
        )
    ) else (
        set "ip_lo_addr_all=!ip_lo_addr_all! !temp_ip_lo_addr!"
    )
)
 
:: Printing to console
::   Adding to Title String
if defined ip_addr (
    echo System IP Addresses: 
    for %%i in (%ip_lo_addr_all%) do echo         %%i
    set "_cmdrc_title=%_cmdrc_title% Local IPS:[%ip_addr: =][%]"
)
:::::::::::::::::::::::::::::::::::::::
 
 
 
:CREATE_CONTEXT_MENUS
if not defined _cmdrc_admin goto skip_CREATE_CONTEXT_MENUS
:: TODO :: check registry
:: TODO :: add if missing
 
:skip_CREATE_CONTEXT_MENUS
 
 
 
:: Pulling Console Encoding  ::::::::::
::   Prints the current              ::
::   console encoding type           ::
::
set "chcp_current="
for /f "tokens=2 delims=:" %%c in ('chcp') do set "chcp_current=%%c"
 
:: Scrubbing output
if defined chcp_current (
    if "%chcp_current:~0,1%" == " " (
        set "chcp_current=%chcp_current:~1%"
    )
)
 
:: Printing to screen
::   If you need to change to UTF8, use this command - chcp 65001
::
 
::   Human readable
if "%chcp_current%" equ "437" (
    set "_cmdrc_chcp_type=OEM - United States"
) 
if "%chcp_current%" equ "65001" (
    set "_cmdrc_chcp_type=UTF-8"
)
 
if defined _cmdrc_chcp_type (
    echo/
    echo Console Encoding: 
    echo         %chcp_current% %_cmdrc_chcp_type%
) else (
    echo/
    echo Console Encoding: 
    echo         %chcp_current%
)
:::::::::::::::::::::::::::::::::::::::
 
 
 
:: Final Title set ::::::::::::::::::::
::   Does persist after endlocal     ::
::
title %_cmdrc_title%
:::::::::::::::::::::::::::::::::::::::
 
:: Print Bar ::::::::::::::::::::::::::
echo [======================================]
 
:: If you wanted to pause or have the prompt delay before
@if defined _pause_flag @echo/ && @echo CMDrc: INFO: Paused: Press any key to continue && @pause 2>&1>nul 
@if defined _delay_flag ( if defined _delay_value ( echo CMDrc: INFO: Delay [%_delay_value%] secs && timeout /t %_delay_value% ) else ( echo CMDrc: INFO: Delay [10] secs && timeout /t 10 ) )
 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                                           ::
:: End of config pull                                                        ::
::   This should only happen once                                            ::
::                                                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
@endlocal
 
:: Double-Triple checking to make sure that the PROMPT value was set properly
@if not defined PROMPT set "PROMPT=%_cmdrc%"
 
 
@echo on
:skip_config_pull
 
:: Making sure that the prompt value is set
@if not "%PROMPT:[]=%" == "%_cmdrc:[]=%" set "PROMPT=%_cmdrc%"

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎