0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【メモ】bashrcに書いておくと便利なやつまとめ (ROS, Proxy, WSL2)

Posted at

環境

Windows11 ( WSL2 [Ubuntu] )

プロキシ設定自動化

net=$(iwgetid -r)
if [ "$net" = "KIT-WLAP2" ]; then
    export http_proxy="<http://wwwproxy.kanazawa-it.ac.jp:8080/>"
    export https_proxy="<http://wwwproxy.kanazawa-it.ac.jp:8080/>"
    export HTTP_PROXY="<http://wwwproxy.kanazawa-it.ac.jp:8080/>"
    export HTTPS_PROXY="<http://wwwproxy.kanazawa-it.ac.jp:8080/>"
    git config --global http.proxy <http://wwwproxy.kanazawa-it.ac.jp:8080/>
    git config --global https.proxy <http://wwwproxy.kanazawa-it.ac.jp:8080/>
    echo "Changed the proxy settings for kit-env"
else
    export http_proxy=""
    export https_proxy=""
    export HTTP_PROXY=""
    export HTTPS_PROXY=""
    git config --global http.proxy ""
    git config --global https.proxy ""
    echo "Cleared the proxy settings"
fi

alias kitproxy='
    export http_proxy="<http://wwwproxy.kanazawa-it.ac.jp:8080/>";
    export https_proxy="<https://wwwproxy.kanazawa-it.ac.jp:8080/>";
    export HTTP_PROXY="<http://wwwproxy.kanazawa-it.ac.jp:8080/>"
    export HTTPS_PROXY="<http://wwwproxy.kanazawa-it.ac.jp:8080/>"
    git config --global http.proxy <http://wwwproxy.kanazawa-it.ac.jp:8080/>;
    git config --global https.proxy <https://wwwproxy.kanazawa-it.ac.jp:8080/>;
    echo "Changed proxy to kit-env"
    '
alias resetproxy='
    export http_proxy="";
    export https_proxy="";
    export HTTP_PROXY=""
    export HTTPS_PROXY=""
    git config --global http.proxy "";
    git config --global https.proxy "";
    echo "Cleared proxy"
    '

時間合わせ・調節

# プロキシ配下、Noプロキシ配下どちらでも時間合わせできるコマンド
# 使い方はターミナルで「ptime」でエンター!パスワードを求められます。
alias ptime='sudo date --set "$(wget -q <http://worldtimeapi.org/api/timezone/Asia/Tokyo.txt> -O - | grep ^datetime | cut -d " " -f 2)"'

ROSの環境設定

# ROS1 NoeticとROS2Foxy共存の場合
ROS_PACKAGE_PATH=/opt/ros/noetic/setup.bash
ROS1_WORKSPATH_PATH=
# ROS1,2のワークスペースを切り替えるときに実行する用(以下noeticとfoxyを切り替える場合)
alias noetic='
    source /opt/ros/noetic/setup.bash;
    source /home/hiroto/noetic_ws/devel/setup.bash;'
alias foxy='
    source /opt/ros/foxy/setup.bash;
    source ~/foxy_ws/install/setup.bash;
    source ~/foxy_ws/install/local_setup.bash;'

# ROS2 Humbleだけの場合
ROS2VER=humble
. /opt/ros/${ROS2VER}/setup.bash
. ~/${ROS2VER}_ws/install/setup.bash;
. ~/${ROS2VER}_ws/install/local_setup.bash;'
export TURTLEBOT3_MODEL=burger

おまけ

個人的なエイリアス設定(コマンド省略したりするヤーツー)

# エイリアス設定 ---------------
VIM=vim
# .bashrcを実行する;編集する
alias sbr="source ~/.bashrc"; alias vbr="${VIM} ~/.bashrc"
# 急にvimrcいじりたくなったときはないかい?「vvr」って打つだけだから少し快適になるよ
alias vvr='${VIM} ~/.vimrc'
# apt -------------------------
alias au="sudo apt update";alias pau="sudo -E apt update"
alias ai="sudo apt install";alias pai="sudo -E apt install"
# github ----------------------
# 個人用アカウントと大学用のアカウントのgitコンフィグを切り替える
alias mygit='
    git config --global user.name (githubのユーザー名);
    git config --global user.email (個人用のメアド);'
alias kitgit='
    git config --global user.name (大学のgithubアカウントのユーザー名);
    git config --global user.email (大学用のメアド);'
# 使い方は「~$ GFIRST (リモートリポジトリのURL)」みたいな感じかな
alias GFIRST="git add . && git commit -m 'first' && git branch -M main && git remote add origin"
# User名・passwordを1時間キャッシュできるよ
alias GCFGC='git config --global credential.helper cache --timeout=3600'
-------------------------------

WSL2 の環境設定

# xlaunchのクライアント?の設定
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0
export LIBGL_ALWAYS_INDIRECT=0
export GAZEBO_IP=127.0.0.1

VSCodeの設定(WSL2)

# vscode ------------------------
export PATH=$PATH:'/mnt/c/Users/ユーザー名/AppData/Local/Programs/Microsoft VS Code/bin'
#--------------------------------

Web開発系の設定

# npm ------------------------------------
alias kitnet='
  以下省略~~~
  ⋮
    # npmのはこんな感じ
    npm -g config set proxy "<http://wwwproxy.kanazawa-it.ac.jp:8080/>";
    npm -g config set https-proxy "<http://wwwproxy.kanazawa-it.ac.jp:8080/>";
    npm -g config set registry "<http://registry.npmjs.org/>"'
alias resetnet='
  以下省略~~~
    ⋮
    npm -g config delete proxy;
    npm -g config delete https-proxy;
    npm -g config delete registry'
# Nodejs ---------------------------------
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
# NVM ------------------------------------
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
#-----------------------------------------

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?