🐸

便利なシェルの使い方

2022/02/08に公開

便利シェルの作り方

使いやすい環境+あまり他のものと被ると問題なので有効化/無効化は手動で行えるシェルを作成してみた。
ターミナルで以下のコマンドを入力してください。

yurilove@user
ahi@user:~$ bm=beat_mario
ahi@user:~$ mkdir $bm 
ahi@user:~$ cd ~/$bm
ahi@user:~/beat_mario$ mkdir .config
ahi@user:~/beat_mario$ cd .config
ahi@user:~/beat_mario/.config$ #私の場合はvscodeでやっていますが、vimなどでも良いです。vimの場合はcodeをvimに変えてくれればできます
ahi@user:~/beat_mario/.config$ code config.sh
ahi@user:~/beat_mario/.config$ code ../enable.sh
ahi@user:~/beat_mario/.config$ code ../disable.sh
ahi@user:~/beat_mario/.config$ code ../get-app.sh

実際に書いてみましょう。

~/beat_mario/.config/config.sh
#!/bin/bash
alias bme="source ~/beat_mario/=enable.sh"
alias bmd="source ~/beat_mario/=disable.sh"
beat_mario_command=false

~/.bashrc
source ~/beat_mario/.config/config.shを追加。

次に本体のシェルを作成

これを使うと有効化できます。

~/beat_mario/enable.sh
#!/bin/bash
#beat_mario command can use eat
bm="beat_mario"
alias dir="cd ~/$bm"
alias edit-enable="code ~/$bm/enable.sh"
alias edit-disable="code ~/$bm/disable.sh"
alias edits="edit-enable;edit-disable"
alias ugc="sudo apt upgrade code"
alias eat="~/$bm/$bm.soft"
alias eirin="eat --help --me"
alias eirn="eirin"
alias ern="eirin"
alias stn="e-list"
alias ssh-key="cd ~/.ssh;ls"
alias want="sudo apt install"
alias want-ok="sudo apt -y install"
alias cl-set="code ./cl.ern"
gimp="/usr/lib/gimp"
alias inkscape="/usr/lib/inkscape/libinkscape_base.so"
mono="/usr/lib/mono"
alias tg="tar -zcvf"
function __untg_of_func
{
    tar -zxvf $1.tar.gz
}
alias untg="__untg_of_func"
alias tb="tar -jcvf"
function __untb_of_func
{
    tar -jxvf $1.tar.bz2
}
alias untb="__untb_of_func"
function __compling_for_clang
{
    if [ $# -eq 1 ]
        then
        clang++ -std=c++17 $1.cpp
        if [ $? -eq 0 ]
            then
            mv a.out $1.soft
        fi
    elif [ $# -eq 0 ]
        then
        clang++ -std=c++17 soft.cpp
        echo $?
        if [ $? -eq 0 ]
            then
            mv a.out soft.soft
        fi
    else
        echo "eirn"
    fi
}
function __setting
{
    #この関数は実はまだ未完成。設定ファイル
    # [1,2,3,"abc"=4]:動的配列及び連想配列
    # 1:数値
    # "abcd":文字列
    # true:boolean
    # undefined:null値。基本的に無視される
    # #:コメント
    local beat_mario_for_tip=""
    while IFS= read -r line; do
        if [ line:0:1 -eq "#" ]
            then
            continue
        fi
        local list=(${line/=/})
        if [ list[1]:0:1 -eq "[" ]
            then
            awk -F "[¥[]"
        fi
        beat_mario_for_tip=list[0]
        $beat_mario_for_tip=list[1]
    done < $1.ern
}
function __cl_dot_eirin
{
    __setting ./cl
    echo "Num:"
}
function __stream_for_zip
{
    echo "done areisiana"
    if [ $1 -eq "--zip" ]
    then
        PTR="zip"
    fi
}
function __stream_for_unzip
{
    echo "done un-areisiana"
}
function __neet_for_eirin
{
    echo "nt $1"
}
function __active_neet_for_eirin
{
    echo "act nt $1"
}
function __ccode
{
    code $1.cpp    
}
function __hcode
{
    code $1.h
}
alias arein="__steram_for_zip"
alias arn="arein"
alias un-arein="__stream_for_unzip"
alias unarn="un-arein"
alias neet="__neet_for_eirin"
alias act-nt="__active_neet_for_eirin"
alias cl="__compling_for_clang"
alias ern-cl="__cl_dot_eirin"
alias ccode="__ccode"
alias hcode="__hcode"
beat_mario_command=true

以下を利用すれば無効化ができます。

~/beat_mario/disable.sh
#!/bin/bash
unalias eat #eat command delete
unalias ern #eirin command delete
unalias eirin
unalias want
unalias want-ok
unalias eirn
unalias arein 
unalias arn
unalias unarn
unalias un-arein
unalias dir
unalias edit-disable
unalias edit-enable
unalias edits
unalias stn
unalias ugc
unalias act-nt
unalias neet
unalias cl
unalias ccode
unalias hcode
unalias ssh-key
unalias cl-set
unset bm
unset __compling_for_clang
unset __untb_of_func
unset __untg_of_func
unset __cl_dot_eirin
unset __stream_for_zip
unset __stream_for_unzip
unset __hcode
unset __ccode
unset __neet_for_eirin
unset __active_neet_for_eirin
beat_mario_command=false

ソフトウェア復旧シェルも作れますよ。

~/beat_mario/get-app.sh
#!/bin/bash
function get-softs
{
    bme
    xgd-open https://azure.microsoft.com/ja-jp/products/visual-studio-code &
    want-ok code
    read -p "visual studio code ok (y/N): " yn
    sudo apt -y update
    want-ok fcitx-mozc
    want-ok task-japansese
    echo "serch j to ja_JP.UTF8"
    sudo dpkg-reconfigure locales
    sudo localectl set-locale LANG=ja_JP.UTF8 LANGAGE="ja_JP:ja"
    source /etc/default/local
    echo "
    Environment=''&name''
    name='GTK_IM_MODULE=fcitx'
    name='QtT_IM_MODULE=fcitx'
    name='XMODIFIERS=@im=fcitx'
    name='GDK_BACKEND=x11'
    "
    code /etc/systemd/user/cros-garcon.service.d/cros-garcon-override.conf
    read -p "config ok? (y/N): " yn
    echo '/usr/bin/fcitx-autostart'>>~/.sommelierrc
    read -p "start install linux soft ok? (y/N): " yn
    case "$yn" in [yY]*) ;; *) echo "abort." ; exit ;; esac
    want-ok gimp
    want-ok inkscape
    want-ok fish
    chmod u+x =enable.sh
    chmod u+x =disable.sh
}
source ./.config/config.sh
get-softs

Discussion