Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Unix shell tricks for developing Qt: Difference between revisions
(Added linebreaks) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
[[Category:Developing_with_Qt]] | [[Category:Developing_with_Qt]] | ||
Here are some aliases and tools that can be useful in a shell session on Linux or | Here are some aliases and tools that can be useful in a shell session on Linux or macOS (or Windows if you are using the version of bash that comes with the git installation). | ||
==git-prompt.sh== | ==git-prompt.sh== | ||
Many distribution packages of git include this shell script, for example in <tt>/usr/share/git</tt>. It may or may not be installed in such a way that it gets parsed in every new login shell; if not, you can add to your own <tt>~/.bashrc</tt> | Many distribution packages of git include this shell script, for example in <tt>/usr/share/git</tt>. It may or may not be installed in such a way that it gets parsed in every new login shell; if not, you can add to your own <tt>~/.bashrc</tt> | ||
<code lang="sh"> | |||
source /usr/share/git/git-prompt.sh | |||
</code> | |||
It will create some bash command completions, so you can e.g. type <tt>git l<tab></tt> to complete the <tt>git log</tt> command. It also defines <tt>__git_ps1</tt>, which can be used as part of your customized shell prompt (preferably including ANSI colors, the time, current directory, the Qt version currently chosen for qtchooser, etc.); you can test it like this | It will create some bash command completions, so you can e.g. type <tt>git l<tab></tt> to complete the <tt>git log</tt> command. It also defines <tt>__git_ps1</tt>, which can be used as part of your customized shell prompt (preferably including ANSI colors, the time, current directory, the Qt version currently chosen for qtchooser, etc.); you can test it like this | ||
<code lang="sh"> | |||
$ echo $(__git_ps1) | |||
(dev>) | |||
</code> | |||
The output means that I'm on "dev" branch and have committed all of my local changes which have not yet been integrated. However, this can slow down your shell when changing directories, because quite some disk activity is necessary to generate that single final character of status. | The output means that I'm on "dev" branch and have committed all of my local changes which have not yet been integrated. However, this can slow down your shell when changing directories, because quite some disk activity is necessary to generate that single final character of status. | ||
Line 21: | Line 21: | ||
These are my favorites so far: | These are my favorites so far: | ||
<code> | <code lang="bash"> | ||
alias git-foreach='git submodule foreach --recursive' | alias git-foreach='git submodule foreach --recursive' | ||
</code> | </code> | ||
Line 27: | Line 27: | ||
is convenient for things like <tt>git-foreach 'git pull --rebase'</tt> to update all submodules to the latest versions of their respective branches (but you could make another alias for that). | is convenient for things like <tt>git-foreach 'git pull --rebase'</tt> to update all submodules to the latest versions of their respective branches (but you could make another alias for that). | ||
<code> | <code lang="bash"> | ||
alias git-cleanall='git submodule foreach --recursive "git clean -dfx" | alias git-cleanall='git submodule foreach --recursive "git clean -dfx"' | ||
</code> | </code> | ||
I use git-cleanall at the top of the repository cloned from qt5.git to ensure that there are no leftover object files before starting a clean build. However, it's better to use shadow builds (run configure and make in a different directory so that the build output stays out of your source tree); the main reasons are that you can use one source tree to build debug and release builds (even for multiple platforms) separately, and your source tree is always clean. But sometimes I still build examples and tests in the source tree, selectively. | I use git-cleanall at the top of the repository cloned from qt5.git to ensure that there are no leftover object files before starting a clean build. However, it's better to use shadow builds (run configure and make in a different directory so that the build output stays out of your source tree); the main reasons are that you can use one source tree to build debug and release builds (even for multiple platforms) separately, and your source tree is always clean. But sometimes I still build examples and tests in the source tree, selectively. | ||
<code> | <code lang="bash"> | ||
alias glog='git log --pretty=format:"%C(auto)%h %C(auto)%d %C(reset) \ | alias glog='git log --pretty=format:"%C(auto)%h %C(auto)%d %C(reset) \ | ||
%s %C(green)(%cr)%C(blue)[%an]%C(reset)" -n10' | %s %C(green)(%cr)%C(blue)[%an]%C(reset)" -n10' | ||
Line 43: | Line 43: | ||
For that I have a shell script, <tt>~/bin/glogg</tt>, like glog but with an extra 'g' to indicate that it does more ;-) (BTW "gløgg" is also a nice Norwegian onomatopoeic word for warm, spiced wine, something like wassail; so using this command gives you a warm Christmas feeling.) | For that I have a shell script, <tt>~/bin/glogg</tt>, like glog but with an extra 'g' to indicate that it does more ;-) (BTW "gløgg" is also a nice Norwegian onomatopoeic word for warm, spiced wine, something like wassail; so using this command gives you a warm Christmas feeling.) | ||
<code> | <code lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
git submodule foreach --recursive --quiet 'echo --- $name\ | git submodule foreach --recursive --quiet 'echo --- $name\ |
Latest revision as of 02:46, 18 May 2017
Here are some aliases and tools that can be useful in a shell session on Linux or macOS (or Windows if you are using the version of bash that comes with the git installation).
git-prompt.sh
Many distribution packages of git include this shell script, for example in /usr/share/git. It may or may not be installed in such a way that it gets parsed in every new login shell; if not, you can add to your own ~/.bashrc
source /usr/share/git/git-prompt.sh
It will create some bash command completions, so you can e.g. type git l<tab> to complete the git log command. It also defines __git_ps1, which can be used as part of your customized shell prompt (preferably including ANSI colors, the time, current directory, the Qt version currently chosen for qtchooser, etc.); you can test it like this
$ echo $(__git_ps1)
(dev>)
The output means that I'm on "dev" branch and have committed all of my local changes which have not yet been integrated. However, this can slow down your shell when changing directories, because quite some disk activity is necessary to generate that single final character of status.
Aliases
These are my favorites so far:
alias git-foreach='git submodule foreach --recursive'
is convenient for things like git-foreach 'git pull --rebase' to update all submodules to the latest versions of their respective branches (but you could make another alias for that).
alias git-cleanall='git submodule foreach --recursive "git clean -dfx"'
I use git-cleanall at the top of the repository cloned from qt5.git to ensure that there are no leftover object files before starting a clean build. However, it's better to use shadow builds (run configure and make in a different directory so that the build output stays out of your source tree); the main reasons are that you can use one source tree to build debug and release builds (even for multiple platforms) separately, and your source tree is always clean. But sometimes I still build examples and tests in the source tree, selectively.
alias glog='git log --pretty=format:"%C(auto)%h %C(auto)%d %C(reset) \
%s %C(green)(%cr)%C(blue)[%an]%C(reset)" -n10'
glog is for showing a short log of the last 10 changes, and highlighting the point at which your local changes diverge from the integrated changes that you got from the remote.
Logging changes in all submodules at once
For that I have a shell script, ~/bin/glogg, like glog but with an extra 'g' to indicate that it does more ;-) (BTW "gløgg" is also a nice Norwegian onomatopoeic word for warm, spiced wine, something like wassail; so using this command gives you a warm Christmas feeling.)
#!/bin/bash
git submodule foreach --recursive --quiet 'echo --- $name\
`git rev-parse --abbrev-ref HEAD`;\
git log\
--pretty=oneline --decorate=short --abbrev-commit\
--date=relative @{u}...HEAD --boundary'