first
This commit is contained in:
177
book/pwsh/01_git.md
Normal file
177
book/pwsh/01_git.md
Normal file
@ -0,0 +1,177 @@
|
||||
# git
|
||||
|
||||
gitはバージョン(version)管理ツールです。linus(linuxを作った人)が開発しています。
|
||||
|
||||
projectにverを付けて、いつでも古いverに戻したり、あるいは新しい機能を別の場所(branch)で開発し、開発が完了したら統合(merge)するようにしたりします。そのほうがprojectが管理しやすいからです。
|
||||
|
||||
```sh
|
||||
$ winget install git.git
|
||||
```
|
||||
|
||||
## tui
|
||||
|
||||
[jesseduffield/lazygit](https://github.com/jesseduffield/lazygit)を使います。
|
||||
|
||||
```
|
||||
$ winget install jesseduffield.lazygit
|
||||
$ lazygit
|
||||
```
|
||||
|
||||
`q`で終了です。`vim`の操作感で使用できます。
|
||||
|
||||
## gitの解説
|
||||
|
||||
gitでやることは基本的なことさえ理解していればokです。
|
||||
|
||||
ようはコードの修正履歴の管理です。
|
||||
|
||||
基本的にprojectフォルダのrootから操作を行います。
|
||||
|
||||
ここに`git init`で`.git/`を作成し、`.git/config`が設定ファイルになります。
|
||||
|
||||
> $project/.git/config
|
||||
|
||||
```sh
|
||||
$ cd $project
|
||||
$ git init
|
||||
$ git remote add origin https://github.com/OWNER/REPOSITORY.git
|
||||
---
|
||||
$ cat .git/config
|
||||
[remote "origin"]
|
||||
url = https://github.com/OWNER/REPOSITORY.git
|
||||
fetch = +refs/heads/*:refs/remotes/origin/*
|
||||
```
|
||||
|
||||
`git remote add`も`.git/config`に書き込んでいるだけなので、直接ファイルを編集しても構いません。git-commandは基本的に`.git/`以下のファイルを変更しているに過ぎないからです。
|
||||
|
||||
### config
|
||||
|
||||
gitは変更履歴ですが、誰がどのような変更をしたかわかるようになっています。
|
||||
|
||||
最初にuserを設定しましょう。mailが必要です。これは、`.git/config`に書いてもいいですが、共通する設定は`~/.gitconfig`に書いておくと便利です。
|
||||
|
||||
> ~/.gitconfig
|
||||
|
||||
```sh
|
||||
[user]
|
||||
name = syui
|
||||
email = syui@users.noreply.github.com
|
||||
```
|
||||
|
||||
もしmailを公開したくない場合は、`$USER@users.noreply.github.com`にしておくとよいでしょう。
|
||||
|
||||
### commit
|
||||
|
||||
```sh
|
||||
# 追加
|
||||
$ echo # title > README.md
|
||||
$ git add README.md
|
||||
|
||||
# コミット
|
||||
$ git commit -m "first"
|
||||
|
||||
# コミットを確定
|
||||
$ git push -u origin master
|
||||
```
|
||||
|
||||
まずaddでファイルをgit管理に追加しています。
|
||||
|
||||
次に、その変更を名前をつけて保存します。これをcommitといいます。
|
||||
|
||||
最後にpushして、localに保存されている変更履歴がurlにupload(アップロード)されます。
|
||||
|
||||
ここまでが一連の流れです。履歴の確認は`git log`です。
|
||||
|
||||
```sh
|
||||
$ git log
|
||||
```
|
||||
|
||||
### branch
|
||||
|
||||
次に、修正を本体のある部分から分離(branch)して行い、最後に本体に取り込むまでの流れを説明します。
|
||||
|
||||
```sh
|
||||
$ git branch -b new-version
|
||||
---
|
||||
# コード(ファイル)を修正する
|
||||
$ vim README.md
|
||||
----
|
||||
#これを繰り返す
|
||||
$ git add .
|
||||
$ git commit -m test-1
|
||||
$ git add .
|
||||
$ git commit -m test-2
|
||||
$ git add .
|
||||
$ git commit -m test-3
|
||||
---
|
||||
# 修正をまとめる
|
||||
$ git rebase @~3
|
||||
r a45ba54 test-1
|
||||
f c3d7514 test-2
|
||||
f 21b8b59 test-3
|
||||
|
||||
update new-version (rでタイトルを変更)
|
||||
---
|
||||
$ git push -f origin new-version
|
||||
---
|
||||
```
|
||||
|
||||
そして、pull-requestを作成し、mergeで本体(origin/master)に取り込みます。
|
||||
|
||||
```sh
|
||||
# branchはいつでも切り替えられる
|
||||
$ git branch
|
||||
$ git checkout master
|
||||
|
||||
# 削除も簡単。変更が取り込まれたら削除して構わない
|
||||
$ git branch -D new-version
|
||||
```
|
||||
|
||||
### push / pull
|
||||
|
||||
gitのすべては`.git/`に保存されています。`.git/config`で設定します。
|
||||
|
||||
push/pull先を変更してみます。
|
||||
|
||||
```diff
|
||||
+[remote "origin"]
|
||||
+ url = git@git.syui.ai:syui/test.git
|
||||
+ fetch = +refs/heads/*:refs/remotes/origin/*
|
||||
-[remote "origin"]
|
||||
- url = https://github.com/OWNER/REPOSITORY.git
|
||||
- fetch = +refs/heads/*:refs/remotes/origin/*
|
||||
```
|
||||
|
||||
```sh
|
||||
$ git pull
|
||||
```
|
||||
|
||||
なお、urlのprotocolはhttpのほか`ssh@github.com`や`git@github.com`などがあります。ただし、urlはprotocolのruleに基づくので注意してください。
|
||||
|
||||
```diff
|
||||
+ git@github.com:syui
|
||||
- git@github.com/syui
|
||||
```
|
||||
|
||||
ssh, gitは鍵認証でpasswordを省略できます。自身が管理するprojectは`git`にしましょう。
|
||||
|
||||
### conflict
|
||||
|
||||
gitを使っていて一番厄介な事は、おそらくconflict(衝突)でしょう。
|
||||
|
||||
例えば、AさんとBさん、Cさんの三人で開発していたとしましょう。
|
||||
|
||||
AさんとBさんは二人とも同じcommitからbranchを切って、作業、つまり、commitを進めていました。一つの丸(commit)があり、そこから別々に枝分かれ(branch)して、丸(commit)が進むイメージです。
|
||||
|
||||
ここで、Bさんのほうが早くにpull-reqを出し、新しいコードが本体にmerge、取り込まれました。
|
||||
|
||||
次にAさんがpull-reqを出します。しかし、mergeしようとすると、できません。conflictが発生したのです。
|
||||
|
||||
AさんもBさんも、同じ箇所に別々の機能を実装しようとしていて、Bさんの変更が先に取り込まれていたからです。
|
||||
|
||||
さて、この解消にはいくつか方法があります。Aさんがconflictを解消するコードに修正するか、mergeするCさんが解消するかです。
|
||||
|
||||
通常は、Aさんがbranchのcommitを最新のコードに対応したものに作り直します。あるいはpull-reqそのものを作り直すかです。通常は前者になります。branchのcommitを進め、conflictが発生しないように修正するのです。この場合、pull-reqを作り直す必要はありません。
|
||||
|
||||
修正は、例えば、他の場所に機能を移すか、Bさんの機能を合体させたものを作るかなどの方法があります。
|
||||
|
107
book/pwsh/02_ssh.md
Normal file
107
book/pwsh/02_ssh.md
Normal file
@ -0,0 +1,107 @@
|
||||
# openssh
|
||||
|
||||
serverにaccess(アクセス)したり、または自身をserverにしたりします。
|
||||
|
||||
```sh
|
||||
$ winget install microsoft.openssh.preview
|
||||
```
|
||||
|
||||
## 他のpcからwindowsに接続する
|
||||
|
||||
windowsをssh serverにする方法です。
|
||||
|
||||
`sshd_config`は`c:/programdata/ssh/sshd_config`にあります。
|
||||
|
||||
> c:/programdata/ssh/sshd_config
|
||||
|
||||
```sh
|
||||
PasswordAuthentication no
|
||||
PermitEmptyPasswords yes
|
||||
AuthorizedKeysFile .ssh/authorized_keys
|
||||
#Match Group administrators
|
||||
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
|
||||
```
|
||||
|
||||
```sh
|
||||
# server
|
||||
$ net start sshd
|
||||
```
|
||||
|
||||
client側で`ssh-keygen`を実行して作成した`.pub`を`~/.ssh/authorized_keys`に追記します。これで鍵認証が通ります。
|
||||
|
||||
```sh
|
||||
# client
|
||||
$ ssh-keygen -f ~/.ssh/test
|
||||
$ cat ~/.ssh/test.pub
|
||||
ssh-rsa AAAAXXXX
|
||||
---
|
||||
# server
|
||||
$ echo "ssh-rsa AAAAXXXX" >> ~/.ssh/authorized_keys
|
||||
$ cat ~/.ssh/authorized_keys
|
||||
ssh-rsa AAAAXXXX
|
||||
```
|
||||
|
||||
この処理は`ssh-copy-id`などが使用できる場合は短縮できます。windowsのopensshが対応しているかはわかりませんが。
|
||||
|
||||
```sh
|
||||
# client
|
||||
$ ssh-copy-id -i ~/.ssh/test $USER@192.168.1.23
|
||||
```
|
||||
|
||||
では他のpcからwindowsにアクセスしてみましょう。
|
||||
|
||||
```sh
|
||||
# client
|
||||
$ ssh -i ~/.ssh/test $USER@192.168.1.23
|
||||
```
|
||||
|
||||
なお、`~/.ssh/config`に書いておくと省略できます。これはclient側です。
|
||||
|
||||
> ~/.ssh/config
|
||||
|
||||
```sh
|
||||
Host windows
|
||||
User syui
|
||||
Hostname 192.168.1.23
|
||||
IdentityFile ~/.ssh/test
|
||||
Port 22
|
||||
```
|
||||
|
||||
```sh
|
||||
# client
|
||||
$ ssh windows
|
||||
```
|
||||
|
||||
file(dir) copyも容易です。
|
||||
|
||||
```sh
|
||||
# server
|
||||
$ echo 12345 > ~/file.txt
|
||||
|
||||
# client
|
||||
$ scp -r windows:file.txt .
|
||||
$ cat file.txt
|
||||
12345
|
||||
```
|
||||
|
||||
## default-shell
|
||||
|
||||
デフォルト(default)のshellを`pwsh`に変えます。
|
||||
|
||||
default-shellを変更した場合の注意ですが、更新した際にerrが出る場合があります。
|
||||
|
||||
> Permission denied (publickey,keyboard-interactive).
|
||||
|
||||
default-shellのpathが違うとpassword/publickey認証のどちらも通りませんので注意してください。
|
||||
|
||||
```sh
|
||||
$ New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force
|
||||
```
|
||||
|
||||
例えば、pwsh-previewを使っている場合はこうなります。使用しているpwshのpathを確認してください。
|
||||
|
||||
```diff
|
||||
+ C:\Program Files\PowerShell\7-preview\pwsh.exe
|
||||
- C:\Program Files\PowerShell\7\pwsh.exe
|
||||
```
|
||||
|
27
book/pwsh/03_ttyd.md
Normal file
27
book/pwsh/03_ttyd.md
Normal file
@ -0,0 +1,27 @@
|
||||
# ttyd
|
||||
|
||||
windows terminalをueのweb browserから操作しようと思ったけど、失敗した話。
|
||||
|
||||
`ttyd`というものを使います。これはwebからterminal操作するためのものです。
|
||||
|
||||
```sh
|
||||
# https://github.com/tsl0922/ttyd
|
||||
$ winget install tsl0922.ttyd
|
||||
|
||||
# windowsで動かすためには互換性をwin8(プロパティ->互換性)にしないといけない
|
||||
# -w ~/ttyd など作業dirを指定しないといけない
|
||||
$ Get-Command ttyd -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
|
||||
|
||||
http://localhost:7681
|
||||
```
|
||||
|
||||
なぜかbrowserからキー入力を受け付けないのか動かなかった。
|
||||
|
||||
## やりたかったこと
|
||||
|
||||
やりたいこととしては、ゲーム内にノートパソコンを置いて、キャラクターが操作しているように見せたい。
|
||||
|
||||
ueのweb browserについては[こちら](/city/05_browser.html)を参照してください。
|
||||
|
||||
なお、ゲーム内から操作できなくても、windowsで操作しているものをwebで共有する方法があればよい。
|
||||
|
14
book/pwsh/04_slidev.md
Normal file
14
book/pwsh/04_slidev.md
Normal file
@ -0,0 +1,14 @@
|
||||
# slidev
|
||||
|
||||
スライドをゲーム内で表示します。発表や配信などに便利です。
|
||||
|
||||
[obs](https://obsproject.com/ja/download)を使って別々に表示する方法もあります。
|
||||
|
||||
localhostでslidevを実行して、ueのweb browserからアクセスします。
|
||||
|
||||
```sh
|
||||
$ npm init slidev@latest
|
||||
# pnpm
|
||||
|
||||
http://localhost:3030/
|
||||
```
|
14
book/pwsh/05_aibot.md
Normal file
14
book/pwsh/05_aibot.md
Normal file
@ -0,0 +1,14 @@
|
||||
# aibot
|
||||
|
||||
`aibot`の構成です。
|
||||
|
||||
- https://git.syui.ai/ai/bot
|
||||
|
||||
|title|body|
|
||||
|---|---|
|
||||
|bot|ai/bot|
|
||||
|server|archlinux|
|
||||
|os|ai/os|
|
||||
|ai|ai/ai|
|
||||
|
||||
|
68
book/pwsh/README.md
Normal file
68
book/pwsh/README.md
Normal file
@ -0,0 +1,68 @@
|
||||
# powershell
|
||||
|
||||
`pwsh`こと`powershell`を使った開発の紹介します。`cmd`を使ってもいいですが、基本的にはterminal(ターミナル)でcommand(コマンド)を実行します。
|
||||
|
||||
まず、`Win`+`R`でpwshを起動します。
|
||||
|
||||
## winget
|
||||
|
||||
package managerの[winget](https://github.com/microsoft/winget-cli)を入れてください。
|
||||
|
||||
- https://github.com/microsoft/winget-cli/releases
|
||||
|
||||
commandは`winget install xxx`です。
|
||||
`.preview`を外すと古いverがinstallされます。
|
||||
|
||||
```sh
|
||||
$ winget install git.git
|
||||
```
|
||||
|
||||
|title|url|command(id)|
|
||||
|---|---|---|
|
||||
|terminal|https://github.com/microsoft/terminal|microsoft.windowsterminal.preview|
|
||||
|pwsh|https://github.com/powershell/powershell|microsoft.powershell.preview|
|
||||
|openssh|https://github.com/powershell/win32-openssh|microsoft.openssh.preview|
|
||||
|wsl|https://github.com/microsoft/wsl|microsoft.wsl|
|
||||
|vscode|https://github.com/microsoft/vscode|microsoft.visualstudiocode|
|
||||
|vim|https://github.com/vim/vim-win32-installer|vim.vim|
|
||||
|git|https://github.com/git/git|git.git|
|
||||
|lazygit|https://github.com/jesseduffield/lazygit|jesseduffield.lazygit|
|
||||
|node|https://github.com/nodejs/node|openjs.nodejs|
|
||||
|nvm|https://github.com/nvm-sh/nvm|coreybutler.nvmforwindows|
|
||||
|python|https://github.com/python|python.python.3.12|
|
||||
|conda|https://github.com/anaconda|anaconda.miniconda3|
|
||||
|
||||
## その他
|
||||
|
||||
|title|command(id)|
|
||||
|---|---|
|
||||
|cuda|nvidia.cuda|
|
||||
|epicgames launcher|epicgames.epicgameslauncher|
|
||||
|blender|blenderfoundation.blender|
|
||||
|discord|discord.discord|
|
||||
|unity|unity.unity|
|
||||
|unity hub|unity.unityhub|
|
||||
|godot|godot.godot|
|
||||
|obs|obsproject.obsstudio|
|
||||
|ollama|ollama.ollama|
|
||||
|
||||
https://github.com/microsoft/winget-pkgs/tree/master/manifests/e/EpicGames/EpicGamesLauncher
|
||||
|
||||
## update
|
||||
|
||||
```sh
|
||||
$ winget source update
|
||||
$ winget upgrade
|
||||
---
|
||||
$ winget upgrade --all
|
||||
```
|
||||
|
||||
## choco, scoop
|
||||
|
||||
昔は`winget`よりも[choco](https://chocolatey.org/install)や[scoop](https://github.com/ScoopInstaller/Scoop)を使っていました。
|
||||
|
||||
## pnpm
|
||||
|
||||
```sh
|
||||
$ npm -g i pnpm
|
||||
```
|
Reference in New Issue
Block a user