Compare commits

..

51 Commits

Author SHA1 Message Date
Florian Tham
367cf32004 Merge remote-tracking branch 'upstream/master' 2024-07-18 13:59:16 +02:00
Will Owens
e606623b71 fix: use grep -E instead of obsolescent egrep (#339)
Grep 3.8 and later nag when using egrep
2024-06-29 13:48:04 -04:00
Mirko Grönroos
a0f9d8fb69 fix: use grep -E instead of obsolescent egrep
Grep 3.8 and later nag when using egrep
2024-05-08 16:44:00 +03:00
Will Owens
c4fbd54a08 fix: Remove nag message for assets management (#337)
Anyone who didn't opt out of the assets management feature (by setting
SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT) would be shown a nag message every
time they started a shell, which adds unnecessary noise.
2024-04-22 09:35:58 -04:00
Kesavan Yogeswaran
9d0f0504ef fix: Remove nag message for assets management
Anyhow who didn't opt out of the assets management feature (by setting
SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT) would be shown a nag message every
time they started a shell, which adds unnecessary noise.
2024-04-06 23:10:25 +00:00
Will Owens
dd6ee875c6 feat: make the design/asset feature optional (#335)
`SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT=true` will
disable the asset management portion of the shell integration.

I don't use it, I've never used it. I know I discussed with @vise890
years ago about how to remove it so we could have a lean core for the
shell & git shortcuts part of this package.

It's still on by default, but adding the environment variable will
disable it, so I'm going to merge this with the longterm intention of
completely splitting these 2 systems apart.
2024-02-27 08:57:54 -05:00
Will Owens
72e31b86e5 feat: make the asset management optional
The environment variable `SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT=true` when set
to will disable the asset management portion of the shell integration.
2024-02-27 08:44:33 -05:00
Will Owens
e0999a1f50 Merge pull request #334 from ghthor/pr/330
Uninstall: lowercase "darwin" on MacOS
2024-02-27 08:00:16 -05:00
Will Owens
b94ff02802 fix: lets compare just lowercased versions of uname output 2024-02-27 06:25:26 -05:00
Will Owens
0cf557c7ba Merge branch 'master' into tobbe-uinstall-darwin 2024-02-27 06:21:36 -05:00
Will Owens
bb7fdaac15 Merge pull request #319 from telzhov/master
Fixed completions for 'gl' and 'gla' aliases

thanks @telzhov for your patience
2024-02-27 06:19:37 -05:00
Will Owens
dac7e1ef20 Merge branch 'master' into master 2024-02-27 06:05:52 -05:00
Will Owens
b2b666b5e8 Merge pull request #333 from ghthor/switch-to-github-actions
- fixed the issues in CI workflow enabling testing osx/linux bash & zsh
- disabled failing zsh tests; they're a real mystery by @jeffbyrnes might take a look at them soon
- fixed scmb_wrapped_shell_commands as array; my initial PR was poorly tested
2024-02-27 05:59:27 -05:00
Will Owens
97193af0a6 [darwin] fix failing root ls test 2024-02-27 05:48:15 -05:00
Will Owens
a3affaf3ce [zsh] remove a something that didn't work 2024-02-27 05:45:57 -05:00
Will Owens
166875cbf8 [zsh] disable failing tests 2024-02-27 05:45:38 -05:00
Will Owens
b2689567e9 [ci] output SHELL value at beginning of tests 2024-02-27 05:27:30 -05:00
Will Owens
13a69cc9c0 [zsh] use interactive shell for running tests 2024-02-27 05:27:26 -05:00
Will Owens
2a05bcc79f [zsh] fix missing history 2024-02-27 05:27:22 -05:00
Will Owens
953e79dd70 [ci] utilize matrix to set TEST_SHELLS 2024-02-23 05:30:00 -05:00
Will Owens
5f58628d8a [shell_shortcuts] fix test by adding dir to / that will match $e1 2024-02-23 05:29:50 -05:00
Will Owens
a46e383a93 [ci] see if ruby fixes ls_with_shortcuts test 2024-02-23 04:16:49 -05:00
Will Owens
71f97bf3cf [shell_aliases] try fix array looping 2024-02-23 04:13:24 -05:00
Will Owens
fd4096ed98 [ci] try running tests in nix-shell 2024-02-23 03:54:10 -05:00
Will Owens
f12bab727b [ci] start conversion to nix 2024-02-23 03:15:38 -05:00
Will Owens
5c814a79d1 [ci] fix current default branch 2024-02-23 03:09:02 -05:00
Will Owens
7742f46257 Merge pull request #332 from ghthor/switch-to-github-actions
[ci] switch to github actions
2024-02-23 03:07:22 -05:00
Will Owens
edff4d20c6 Merge remote-tracking branch 'origin/master' into HEAD 2024-02-23 02:50:35 -05:00
Will Owens
cac8c5b00a Merge pull request #331 from scmbreeze/fix-wrapped-commands-example
[example] switch to declaring wrapped commands as an array
2024-02-16 16:03:14 -05:00
Will Owens
a7ab2e831f [example] switch to declaring wrapped commands as an array 2024-02-16 15:59:48 -05:00
Tobbe Lundberg
821097eec9 Uninstall: lowercase "darwin" on MacOS 2023-11-19 11:31:30 +01:00
Jeff Byrnes
c9045bd3e1 Replace Travis CI with GitHub Actions
* Use GH Actions Matrices for multi-OS & multi-shell testing
* Drop helper script for installing zsh on Linux
    - Should be available by default on ubuntu-latest
2023-07-16 16:01:29 -04:00
Jeff Byrnes
ee57debc69 Merge branch 'master' of github.com:scmbreeze/scm_breeze
* 'master' of github.com:scmbreeze/scm_breeze:
  fix rc file suffix in README
  Return error code from git branch command.
  Use File.exist over deprecated File.exists
  Speed up and simplify parse_git_branch
  Define git functions with parentheses instead of curly braces, so that we can press Ctrl+C to quit the commit prompt without terminating the shell session. (Parentheses run the function in a subshell.)
2023-07-16 16:00:07 -04:00
Will Owens
5f2d259029 Merge pull request #327 from alexconlin/patch-1
fix rc file suffix in README
2023-07-08 07:45:00 -04:00
Alex Conlin
c12c5e3665 fix rc file suffix in README 2023-07-06 10:53:03 +01:00
Will Owens
b53d1ed3a2 Merge pull request #324 from mmcrockett/master
git:branch legacy return no error code when git branch succeeds.
2023-01-28 13:37:14 -05:00
mike crockett
57e6d583f7 Return error code from git branch command. 2023-01-20 14:01:20 -06:00
Will Owens
3e59bc9032 Merge pull request #323 from kimmobrunfeldt/master
Use File.exist over deprecated File.exists
2023-01-13 05:57:51 -05:00
Kimmo Brunfeldt
ae2dd1a559 Use File.exist over deprecated File.exists 2023-01-12 08:43:16 +02:00
Nathan Broadbent
0e21e89f3a Speed up and simplify parse_git_branch 2022-11-17 02:27:46 +13:00
telzhov
a4308179ad Fixed completions for 'gl' and 'gla' aliases 2022-11-10 07:48:25 +03:00
Nathan Broadbent
136fb6b4ee Define git functions with parentheses instead of curly braces, so that we can press Ctrl+C to quit the commit prompt without terminating the shell session. (Parentheses run the function in a subshell.) 2022-10-29 15:12:06 +13:00
Jeff Byrnes
c82b7f23b7 Merge remote-tracking branch 'upstream/master'
* upstream/master:
  Switch to output parse of `--version` to determine ls flavor
  Update installation repo URL
2022-07-28 14:09:11 -04:00
Will Owens
6c85b866af Merge pull request #318 from ghthor/test-bsd-ls
Switch to output parse of `--version` to determine ls version
2022-06-25 11:15:21 -07:00
Will Owens
38143cd5ec Switch to output parse of --version to determine ls flavor 2022-06-23 15:01:58 -04:00
Will Owens
62b73f7e78 Update installation repo URL
Github has stopped supporting `git://` protocol URLs

See: https://github.blog/2021-09-01-improving-git-protocol-security-github/
2022-03-28 08:57:48 -07:00
Jeff Byrnes
27cf045414 Merge remote-tracking branch 'origin/master'
* origin/master:
  Fix shell wrapping for exes with space in path.
  README.md: add remark that some commands don't work w/o ruby
2022-03-25 11:50:52 -04:00
Will Owens
24d08174e7 Merge pull request #299 from jameskeane/wsl-spaces-fix
Fix shell wrapping for exes with space in path.
2022-03-23 18:03:24 -04:00
Jeff Byrnes
22023c7445 Merge branch 'scmbreeze:master' into main 2021-07-26 14:00:31 -04:00
Jeff Byrnes
1a7e93c815 Update Pull Request alias to use gh 2021-01-05 16:22:53 -05:00
Test User
50ccfd9e97 Fix shell wrapping for exes with space in path.
I experienced this using VS Code in WSL, the `code` CLI is in the
Windows `PATH` that has a space in my user name.

Fixes #294.
2020-02-04 13:23:25 -05:00
19 changed files with 260 additions and 207 deletions

40
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
test_shell:
- bash
- zsh
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
nix_path: nixpkgs=channel:nixos-unstable
- run: |
git config --global init.defaultBranch master
git config --global user.name scm_breeze@scm_breeze
git config --global user.email "SCM Breeze"
- name: test
env:
TEST_SHELLS: ${{ matrix.test_shell }}
run: nix-shell -p ruby $TEST_SHELLS --command ./run_tests.sh
# - run: nix-shell -p shunit2 -i ./run_tests.sh
# - run: nix build
# - run: nix flake check

View File

@@ -1,18 +0,0 @@
os:
- linux
- osx
env:
- TEST_SHELLS=bash
- TEST_SHELLS=zsh
sudo: required
install:
- ./test/support/travisci_deps.sh
before_script:
- echo -e "test_repo_11\ntest_repo_1" | sort
script:
- ./run_tests.sh

View File

@@ -27,7 +27,7 @@ features.
## Installation
```bash
git clone git://github.com/scmbreeze/scm_breeze.git ~/.scm_breeze
git clone https://github.com/scmbreeze/scm_breeze.git ~/.scm_breeze
~/.scm_breeze/install.sh
source ~/.bashrc # or source "${ZDOTDIR:-$HOME}/.zshrc"
```
@@ -181,7 +181,7 @@ doesn't need to 'learn' anything, and it can do SCM-specific stuff like:
The default alias for `git_index` is 'c', which might stand for 'code'
You will first need to configure your repository directory by setting `GIT_REPO_DIR` in `~/.git.sbmrc`.
You will first need to configure your repository directory by setting `GIT_REPO_DIR` in `~/.git.scmbrc`.
Then, build the index:

View File

@@ -126,6 +126,6 @@ git_add_and_amend_commit_keys="\C-xz" # CTRL+x, z
# Expand numbered args for common shell commands
shell_command_wrapping_enabled="true"
# Here you can tweak the list of wrapped commands.
scmb_wrapped_shell_commands="vim emacs gedit cat rm cp mv ln cd ls less subl code"
scmb_wrapped_shell_commands=(vim emacs gedit cat rm cp mv ln cd ls less subl code)
# Add numbered shortcuts to output of ls -l, just like 'git status'
shell_ls_aliases_enabled="true"

View File

@@ -120,11 +120,12 @@ if [ "$git_setup_aliases" = "yes" ]; then
__git_alias "$git_restore_alias" 'git' 'restore'
# Custom default format for git log
git_log_command="log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
__git_alias "$git_log_alias" 'git' "$git_log_command"
git_log_command=('log' '--graph' "--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
'--abbrev-commit')
__git_alias "$git_log_alias" 'git' "${git_log_command[@]}"
# Same as the above, but displays all the branches and remotes
__git_alias "$git_log_all_alias" 'git' "$git_log_command" '--branches' '--remotes'
__git_alias "$git_log_all_alias" 'git' "${git_log_command[@]}" '--branches' '--remotes'
# Standard commands
__git_alias "$git_clone_alias" 'git' 'clone'
@@ -176,8 +177,8 @@ if [ "$git_setup_aliases" = "yes" ]; then
_alias "$git_log_graph_all_alias" 'git log --all --graph --oneline --decorate --date-order'
_alias "$git_add_all_alias" 'git add --all .'
# Hub aliases (https://github.com/github/hub)
_alias "$git_pull_request_alias" 'git pull-request'
# GitHub CLI aliases (https://github.com/cli/cli)
_alias "$git_pull_request_alias" 'gh pr'
fi

View File

@@ -17,7 +17,7 @@ function _scmb_git_branch_shortcuts {
# Fall back to normal git branch, if any unknown args given
if [[ "$($_git_cmd branch | wc -l)" -gt 300 ]] || ([[ -n "$@" ]] && [[ "$@" != "-a" ]]); then
exec_scmb_expand_args $_git_cmd branch "$@"
return 1
return $?
fi
# Use ruby to inject numbers into git branch output

View File

@@ -140,7 +140,7 @@ $pad$c_dark [$c_rst$e$c_dark] $c_group$relative$c_rst"
# Export numbered variables in the order they are displayed.
# (Exports full path, but displays relative path)
# fetch first file (in the case of oldFile -> newFile) and remove quotes
local filename=$(eval echo $(echo ${stat_file[$i]} | egrep -o '^"([^\\"]*(\\.[^"]*)*)"|^[^ ]+'))
local filename=$(eval echo $(echo ${stat_file[$i]} | grep -E -o '^"([^\\"]*(\\.[^"]*)*)"|^[^ ]+'))
export $git_env_char$e="$project_root/$filename"
let e++
done

View File

@@ -171,7 +171,7 @@ function is_git_dirty {
[[ $($GIT_BINARY status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
$GIT_BINARY branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
git rev-parse --abbrev-ref HEAD 2> /dev/null
}
# If the working directory is clean, update the git repository. Otherwise, show changes.

View File

@@ -4,7 +4,6 @@
# Released under the LGPL (GNU Lesser General Public License)
# ------------------------------------------------------------------------------
if sed -E 's///g' </dev/null &>/dev/null; then
SED_REGEX_ARG="E"
elif sed -r 's///g' </dev/null &>/dev/null; then
@@ -13,7 +12,6 @@ else
echo "Cannot determine extended regex argument for sed! (Doesn't respond to either -E or -r)"
fi
# Wrap common commands with numeric argument expansion.
# Prepends everything with exec_scmb_expand_args,
# even if commands are already aliases or functions
@@ -21,14 +19,14 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
# Do it in a function so we don't bleed variables
function _git_wrap_commands() {
# Define 'whence' for bash, to get the value of an alias
type whence > /dev/null 2>&1 || function whence() { LC_MESSAGES="C" type "$@" | sed -$SED_REGEX_ARG -e "s/.*is aliased to \`//" -e "s/'$//"; }
type whence >/dev/null 2>&1 || function whence() { LC_MESSAGES="C" type "$@" | sed -$SED_REGEX_ARG -e "s/.*is aliased to \`//" -e "s/'$//"; }
local cmd=''
for cmd in $scmb_wrapped_shell_commands; do
for cmd in "${scmb_wrapped_shell_commands[@]}"; do
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: Wrapping $cmd..."; fi
# Special check for 'cd', to make sure SCM Breeze is loaded after RVM
if [ "$cmd" = 'cd' ]; then
if [ -e "$HOME/.rvm" ] && ! type rvm > /dev/null 2>&1; then
if [ -e "$HOME/.rvm" ] && ! type rvm >/dev/null 2>&1; then
echo -e "\\033[0;31mSCM Breeze must be loaded \\033[1;31mafter\\033[0;31m RVM, otherwise there will be a conflict when RVM wraps the 'cd' command.\\033[0m"
echo -e "\\033[0;31mPlease move the line that loads SCM Breeze to the bottom of your ~/.bashrc\\033[0m"
continue
@@ -39,12 +37,14 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
# Don't do anything if command already aliased, or not found.
*'exec_scmb_expand_args'*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is already wrapped"; fi;;
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is already wrapped"; fi
;;
*'not found'*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi;;
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi
;;
*'aliased to'*|*'is an alias for'*)
*'aliased to'* | *'is an alias for'*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an alias"; fi
# Store original alias
local original_alias="$(whence $cmd)"
@@ -54,15 +54,16 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
# Detect original $cmd type, and escape
case "$(LC_MESSAGES="C" type "$cmd" 2>&1)" in
# Escape shell builtins with 'builtin'
*'is a shell builtin'*) local escaped_cmd="builtin $cmd";;
*'is a shell builtin'*) local escaped_cmd="builtin $cmd" ;;
# Get full path for files with 'find_binary' function
*) local escaped_cmd="$(find_binary $cmd)";;
*) local escaped_cmd="$(find_binary $cmd)" ;;
esac
# Expand original command into full path, to avoid infinite loops
local expanded_alias="$(echo $original_alias | sed -$SED_REGEX_ARG "s%(^| )$cmd($| )%\\1$escaped_cmd\\2%")"
# Wrap previous alias with escaped command
alias $cmd="exec_scmb_expand_args $expanded_alias";;
alias $cmd="exec_scmb_expand_args $expanded_alias"
;;
*'is a'*'function'*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a function"; fi
@@ -71,47 +72,50 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
# Remove function
unset -f "$cmd"
# Create function that wraps old function
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }";;
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }"
;;
*'is a shell builtin'*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a shell builtin"; fi
# Handle shell builtin commands
alias $cmd="exec_scmb_expand_args builtin $cmd";;
alias $cmd="exec_scmb_expand_args builtin $cmd"
;;
*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an executable file"; fi
# Otherwise, command is a regular script or binary,
# and the full path can be found with 'find_binary' function
alias $cmd="exec_scmb_expand_args $(find_binary $cmd)";;
alias $cmd="exec_scmb_expand_args '$(find_binary $cmd)'"
;;
esac
done
# Clean up
declare -f whence > /dev/null && unset -f whence
declare -f whence >/dev/null && unset -f whence
}
_git_wrap_commands
fi
# Function wrapper around 'll'
# Adds numbered shortcuts to output of ls -l, just like 'git status'
if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/null 2>&1; then
if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby >/dev/null 2>&1; then
# BSD ls is different to Linux (GNU) ls
# Test for BSD ls
if ! ls --color=auto > /dev/null 2>&1; then
if ! (ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then
# ls is BSD
_ls_bsd="BSD"
fi
# Test if readlink supports -f option, test for greadlink on Mac, then fallback to perl
if \readlink -f / > /dev/null 2>&1; then
if \readlink -f / >/dev/null 2>&1; then
_abs_path_command=(readlink -f)
elif greadlink -f / > /dev/null 2>&1; then
elif greadlink -f / >/dev/null 2>&1; then
_abs_path_command=(greadlink -f)
else
_abs_path_command=(perl -e 'use Cwd abs_path; print abs_path(shift)')
fi
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
unalias ll >/dev/null 2>&1
unset -f ll >/dev/null 2>&1
function ls_with_file_shortcuts {
local ll_output
local ll_command # Ensure sort ordering of the two invocations is the same
@@ -142,7 +146,7 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
else # It's a file, expand the current directory
rel_path=.
fi
elif [[ -d $arg || ( -f $arg && $rel_path != . ) ]]; then
elif [[ -d $arg || (-f $arg && $rel_path != .) ]]; then
if [[ -f $arg ]]; then arg=$PWD; fi # Get directory for current argument
# We've already seen a different directory. Quit to avoid damage (issue #274)
printf 'scm_breeze: Cannot list relative to both directories:\n %s\n %s\n' "$arg" "$rel_path" >&2
@@ -159,7 +163,7 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
if [ -e "$HOME"/.user_sym ]; then
# Little bit of ruby golf to rejustify the user/group/size columns after replacement
# TODO(ghthor): Convert this to a cat <<EOF to improve readibility
function rejustify_ls_columns(){
function rejustify_ls_columns() {
ruby -e "o=STDIN.read;re=/^(([^ ]* +){2})(([^ ]* +){3})/;\
u,g,s=o.lines.map{|l|l[re,3]}.compact.map(&:split).transpose.map{|a|a.map(&:size).max+1};\
puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}"
@@ -168,12 +172,12 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
local USER_SYM=$(/bin/cat $HOME/.user_sym)
if [ -f "$HOME/.staff_sym" ]; then
local STAFF_SYM=$(/bin/cat $HOME/.staff_sym)
ll_output=$(echo "$ll_output" | \
\sed -$SED_REGEX_ARG "s/ $USER staff/ $USER_SYM $STAFF_SYM /g" | \
ll_output=$(echo "$ll_output" |
\sed -$SED_REGEX_ARG "s/ $USER staff/ $USER_SYM $STAFF_SYM /g" |
rejustify_ls_columns)
else
ll_output=$(echo "$ll_output" | \
\sed -$SED_REGEX_ARG "s/ $USER/ $USER_SYM /g" | \
ll_output=$(echo "$ll_output" |
\sed -$SED_REGEX_ARG "s/ $USER/ $USER_SYM /g" |
rejustify_ls_columns)
fi
fi
@@ -186,7 +190,8 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
fi
# Use ruby to inject numbers into ls output
echo "$ll_output" | ruby -e "$( \cat <<EOF
echo "$ll_output" | ruby -e "$(
\cat <<EOF
output = STDIN.read
e = 1
re = /^(([^ ]* +){8})/
@@ -196,7 +201,7 @@ output.lines.each do |line|
e += 1
end
EOF
)"
)"
# Set numbered file shortcut in variable
local e=1

View File

@@ -88,7 +88,7 @@ puts "%s#%s On branch: %s#{@branch}#{difference}%s %s| [%s*%s]%s => $#{ENV["gi
]
def has_modules?
@has_modules ||= File.exists?(File.join(@project_root, '.gitmodules'))
@has_modules ||= File.exist?(File.join(@project_root, '.gitmodules'))
end
# Index modification states

View File

@@ -209,7 +209,7 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
# * Execute prerequisite commands if message given, abort if not
# * Pipe commit message to 'git commit'
# * Add escaped commit command and unescaped message to bash history.
git_commit_prompt() {
git_commit_prompt() (
local commit_msg
local saved_commit_msg
if [ -f "/tmp/.git_commit_message~" ]; then
@@ -268,10 +268,10 @@ git_commit_prompt() {
# Delete saved commit message if commit was successful
rm -f "/tmp/.git_commit_message~"
fi
}
)
# Prompt for commit message, then commit all modified and untracked files.
git_commit_all() {
git_commit_all() (
fail_if_not_git_repo || return 1
changes=$(git status --porcelain | wc -l | tr -d ' ')
if [ "$changes" -gt 0 ]; then
@@ -283,10 +283,10 @@ git_commit_all() {
else
echo "# No changed files to commit."
fi
}
)
# Add paths or expanded args if any given, then commit all staged changes.
git_add_and_commit() {
git_add_and_commit() (
fail_if_not_git_repo || return 1
git_silent_add_shortcuts "$@"
changes=$(git diff --cached --numstat | wc -l)
@@ -296,4 +296,4 @@ git_add_and_commit() {
else
echo "# No staged changes to commit."
fi
}
)

View File

@@ -3,6 +3,8 @@
failed=false
env | grep ^SHELL
# allow list of shells to run tests in to be overriden by environment variable
# if empty or null, use defaults
if [ -z "$TEST_SHELLS" ]; then
@@ -15,6 +17,7 @@ for test in $(find test/lib -name *_test.sh); do
for shell in $TEST_SHELLS; do
echo "== Running tests with [$shell]: $test"
$shell $test || failed=true
printf '==\n\n'
done
done

View File

@@ -9,8 +9,12 @@ export scmbDir="$(dirname ${BASH_SOURCE:-$0})"
# Shared functions
source "$scmbDir/lib/scm_breeze.sh"
# Design assets management
source "$scmbDir/lib/design.sh"
SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT=${SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT:-""}
if [ "$SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT" != "true" ]; then
source "$scmbDir/lib/design.sh"
fi
# Git
# ------------------------------------------------------------
@@ -24,13 +28,14 @@ if [[ -s "$HOME/.git.scmbrc" ]]; then
source "$scmbDir/lib/git/branch_shortcuts.sh"
source "$scmbDir/lib/git/grep_shortcuts.sh"
source "$scmbDir/lib/git/shell_shortcuts.sh"
if [ "$SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT" != "true" ]; then
source "$scmbDir/lib/git/repo_index.sh"
fi
source "$scmbDir/lib/git/tools.sh"
if ! type ruby > /dev/null 2>&1; then
if ! type ruby >/dev/null 2>&1; then
# If Ruby is not installed, fall back to the
# slower bash/zsh implementation of 'git_status_shortcuts'
source "$scmbDir/lib/git/fallback/status_shortcuts_shell.sh"
fi
fi

View File

@@ -11,3 +11,7 @@ export design_av_dirs="Animations Videos Flash Music Samples"
# Directories for global design assets (not symlinked into projects)
export design_ext_dirs="Fonts IconSets"
# Set =true to disable the design/assets management features
# export SCM_BREEZE_DISABLE_ASSETS_MANAGEMENT=true
# vi: ft=sh

0
test.sh Normal file
View File

View File

@@ -7,11 +7,13 @@
#
# Unit tests for shell command wrapping
export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
export scmbDir="$(cd -P "$(dirname "$0")" && pwd)/../../.."
# Zsh compatibility
if [ -n "${ZSH_VERSION:-}" ]; then
shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit
shell="zsh"
SHUNIT_PARENT=$0
setopt shwordsplit
else
# Bash needs this option so that 'alias' works in a non-interactive shell
shopt -s expand_aliases
@@ -25,7 +27,7 @@ source "$scmbDir/lib/scm_breeze.sh"
#-----------------------------------------------------------------------------
oneTimeSetUp() {
export shell_command_wrapping_enabled="true"
export scmb_wrapped_shell_commands="not_found cat rm cp mv ln cd sed"
export scmb_wrapped_shell_commands=("not_found" "cat" "rm" "cp" "mv" "ln" "cd" "sed")
export shell_ls_aliases_enabled="true"
alias rvm="test" # Ensure tests run if RVM isn't loaded but $HOME/.rvm is present
@@ -47,21 +49,27 @@ oneTimeSetUp() {
# Test already wrapped commands
alias cat="exec_scmb_expand_args $cat_path"
root_test_dir=/aaa
if [ "$(uname)" = "Darwin" ]; then
root_test_dir=/Applications
else
sudo mkdir $root_test_dir
fi
# Run shortcut wrapping
source "$scmbDir/lib/git/shell_shortcuts.sh"
# Define 'whence' function for Bash.
# Must come after sourcing shell_shortcuts
type whence > /dev/null 2>&1 || function whence() { type "$@" | sed -e "s/.*is aliased to \`//" -e "s/'$//"; }
type whence >/dev/null 2>&1 || function whence() { type "$@" | sed -e "s/.*is aliased to \`//" -e "s/'$//"; }
}
# Helper function to test that alias is defined properly.
# (Works for both zsh and bash)
assertAliasEquals(){
assertAliasEquals() {
assertEquals "$1" "$(whence $2)"
}
#-----------------------------------------------------------------------------
# Setup and tear down
#-----------------------------------------------------------------------------
@@ -70,7 +78,6 @@ setUp() {
unset QUOTING_STYLE # Use default quoting style for ls
}
#-----------------------------------------------------------------------------
# Unit tests
#-----------------------------------------------------------------------------
@@ -105,7 +112,7 @@ test_ls_with_file_shortcuts() {
# Run command in shell, load output from temp file into variable
# (This is needed so that env variables are exported in the current shell)
temp_file=$(mktemp -t scm_breeze.XXXXXXXXXX)
ls_with_file_shortcuts > "$temp_file"
ls_with_file_shortcuts >"$temp_file"
ls_output=$(<"$temp_file" strip_colors)
# Compare as fixed strings (F), instead of normal grep behavior
@@ -123,7 +130,7 @@ test_ls_with_file_shortcuts() {
assertEquals "$TEST_DIR/test_file" "$e5"
# Test ls with subdirectory
ls_with_file_shortcuts 'a "b"' > $temp_file
ls_with_file_shortcuts 'a "b"' >$temp_file
ls_output=$(<$temp_file strip_colors)
assertIncludes "$ls_output" '[1] c' F
# Test that env variable is set correctly
@@ -141,10 +148,16 @@ test_ls_with_file_shortcuts() {
assertFalse 'Fails on <directory> <directory>/<file>' 'ls_with_file_shortcuts 1 1/file'
# Files under the root directory
assertTrue 'Shortcuts under /' 'ls_with_file_shortcuts / > /dev/null && [[ $e1 =~ ^/[^/]+$ ]]'
assertTrue 'Shortcuts under /' 'ls_with_file_shortcuts / >/dev/null && [[ $e1 =~ ^/[^/]+$ ]]'
ls_with_file_shortcuts / >/dev/null
assertTrue "$e1 == $root_test_dir" '[[ "$e1" == "$root_test_dir" ]]'
cd -
rm -r "$TEST_DIR" "$temp_file"
if [ "$(uname)" != "Darwin" ]; then
sudo rmdir "$root_test_dir"
fi
}
# load and run shUnit2

View File

@@ -7,10 +7,15 @@
#
# Unit tests for git shell scripts
export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
export scmbDir="$(cd -P "$(dirname "$0")" && pwd)/../../.."
# Zsh compatibility
if [ -n "${ZSH_VERSION:-}" ]; then shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit; fi
if [ -n "${ZSH_VERSION:-}" ]; then
shell="zsh"
SHUNIT_PARENT=$0
setopt shwordsplit
setopt append_history
fi
# Load test helpers
source "$scmbDir/test/support/test_helper.sh"
@@ -19,7 +24,6 @@ source "$scmbDir/test/support/test_helper.sh"
source "$scmbDir/lib/scm_breeze.sh"
source "$scmbDir/lib/git/status_shortcuts.sh"
# Setup and tear down
#-----------------------------------------------------------------------------
oneTimeSetUp() {
@@ -40,10 +44,9 @@ setupTestRepo() {
rm -rf "${testRepo}"
mkdir -p "$testRepo"
cd "$testRepo"
git init > /dev/null
git init >/dev/null
}
#-----------------------------------------------------------------------------
# Unit tests
#-----------------------------------------------------------------------------
@@ -52,19 +55,37 @@ test_scmb_expand_args() {
local e1="one" e2="two" e3="three" e4="four" e5="five" e6="six" e7='$dollar' e8='two words'
local error="Args not expanded correctly"
assertEquals "$error" 'one three six' \
"$(eval args="$(scmb_expand_args 1 3 6)"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args 1 3 6)"
token_quote "${args[@]}"
)"
assertEquals "$error" 'one two three five' \
"$(eval args="$(scmb_expand_args 1-3 5)"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args 1-3 5)"
token_quote "${args[@]}"
)"
assertEquals "$error" '\$dollar two three four one' \
"$(eval args="$(scmb_expand_args 7 2-4 1)"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args 7 2-4 1)"
token_quote "${args[@]}"
)"
# Test that any args with spaces remain quoted
assertEquals "$error" '-m Test\ Commit\ Message one' \
"$(eval args="$(scmb_expand_args -m "Test Commit Message" 1)"; token_quote "${args[@]}")"
assertEquals "$error" '-ma Test\ Commit\ Message Unquoted'\
"$(eval args="$(scmb_expand_args -ma "Test Commit Message" "Unquoted")"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args -m "Test Commit Message" 1)"
token_quote "${args[@]}"
)"
assertEquals "$error" '-ma Test\ Commit\ Message Unquoted' \
"$(
eval args="$(scmb_expand_args -ma "Test Commit Message" "Unquoted")"
token_quote "${args[@]}"
)"
assertEquals "$error" '\$dollar one two\ words' \
"$(eval args="$(scmb_expand_args 7 1-1 8)"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args 7 1-1 8)"
token_quote "${args[@]}"
)"
# Keep this code for use when minimum versions of {ba,z}sh can be increased.
# See token_quote() source and https://github.com/scmbreeze/scm_breeze/issues/260
@@ -89,14 +110,23 @@ test_scmb_expand_args() {
test_exec_scmb_expand_args() {
local e1="one" e2="a b c" e3='$dollar' e4="single'quote" e5='double"quote' e6='a(){:;};a&'
assertEquals "literals with spaces not preserved" 'foo bar\ baz' \
"$(eval args="$(scmb_expand_args foo 'bar baz')"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args foo 'bar baz')"
token_quote "${args[@]}"
)"
assertEquals "variables with spaces not preserved" 'one a\ b\ c' \
"$(eval args="$(scmb_expand_args 1-2)"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args 1-2)"
token_quote "${args[@]}"
)"
# Expecting text: '$dollar' "single'quote" 'double"quote'
# Generate quoted expected string with: token_quote "$(cat)" then copy/paste, ^D
assertEquals "special characters are preserved" \
'\$dollar single\'\''quote double\"quote a\(\)\{:\;\}\;a\&' \
"$(eval args="$(scmb_expand_args 3-6)"; token_quote "${args[@]}")"
"$(
eval args="$(scmb_expand_args 3-6)"
token_quote "${args[@]}"
)"
# Keep this code for use when minimum versions of {ba,z}sh can be increased.
# See token_quote() source and https://github.com/scmbreeze/scm_breeze/issues/260
@@ -129,7 +159,7 @@ test_git_status_shortcuts() {
touch new_file
touch untracked_file
git add new_file
echo "changed" > new_file
echo "changed" >new_file
rm deleted_file
verboseGitCommands
@@ -153,7 +183,7 @@ test_git_status_shortcuts() {
# Run command in shell, load output from temp file into variable
# (This is needed so that env variables are exported in the current shell)
temp_file=$(mktemp -t scm_breeze.XXXXXXXXXX)
git_status_shortcuts > $temp_file
git_status_shortcuts >$temp_file
git_status=$(<$temp_file strip_colors)
assertIncludes "$git_status" "new file: *\[1\] *new_file" || return
@@ -202,7 +232,6 @@ test_git_status_produces_relative_paths() {
assertIncludes "$git_status" "../../../dir2/testfile" || return
}
test_git_status_shortcuts_merge_conflicts() {
setupTestRepo
@@ -210,23 +239,23 @@ test_git_status_shortcuts_merge_conflicts() {
# Set up every possible merge conflict
touch both_modified both_deleted deleted_by_them deleted_by_us
echo "renamed file needs some content" > renamed_file
echo "renamed file needs some content" >renamed_file
git add both_modified both_deleted renamed_file deleted_by_them deleted_by_us
git commit -m "First commit"
git checkout -b conflict_branch
echo "added by branch" > both_added
echo "branch line" > both_modified
echo "deleted by us" > deleted_by_us
echo "added by branch" >both_added
echo "branch line" >both_modified
echo "deleted by us" >deleted_by_us
git rm deleted_by_them both_deleted
git mv renamed_file renamed_file_on_branch
git add both_added both_modified deleted_by_us
git commit -m "Branch commit"
git checkout master
echo "added by master" > both_added
echo "master line" > both_modified
echo "deleted by them" > deleted_by_them
echo "added by master" >both_added
echo "master line" >both_modified
echo "deleted by them" >deleted_by_them
git rm deleted_by_us both_deleted
git mv renamed_file renamed_file_on_master
git add both_added both_modified deleted_by_them
@@ -247,7 +276,6 @@ test_git_status_shortcuts_merge_conflicts() {
assertIncludes "$git_status" "added by us: *\[[0-9]*\] *renamed_file_on_master" || return
}
test_git_status_shortcuts_max_changes() {
setupTestRepo
@@ -269,14 +297,13 @@ test_git_status_shortcuts_max_changes() {
export gs_max_changes="20"
}
test_git_add_shortcuts() {
setupTestRepo
touch a b c d e f g h i j
# Show git status, which sets up env variables
git_status_shortcuts > /dev/null
git_add_shortcuts 2-4 7 8 > /dev/null
git_status_shortcuts >/dev/null
git_add_shortcuts 2-4 7 8 >/dev/null
git_status=$(git_status_shortcuts 1 | strip_colors)
for c in b c d g h; do
@@ -295,14 +322,14 @@ test_git_commit_prompt() {
export HISTSIZE=1000
touch a b c d
git add . > /dev/null
git add . >/dev/null
# Zsh 'vared' doesn't handle input via pipe, so replace with function that reads into commit_msg variable.
function vared(){ read commit_msg; }
function vared() { read commit_msg; }
# Test the git commit prompt, by piping a commit message
# instead of user input.
echo "$commit_msg" | git_commit_prompt > /dev/null
echo "$commit_msg" | git_commit_prompt >/dev/null
git_show_output=$(git show --oneline --name-only)
assertIncludes "$git_show_output" "$commit_msg"
@@ -310,12 +337,14 @@ test_git_commit_prompt() {
# Test that history was appended correctly.
if [[ $shell == "zsh" ]]; then
test_history="$(history)"
# TODO(ghthor): zsh isn't working here
# assertIncludes "$test_history" "git commit -m \"$dbl_escaped_msg\""
else
# Need to load history from $HISTFILE
# (Couldn't get the 'history' builtin to work during tests.)
test_history="$(cat $HISTFILE)"
fi
assertIncludes "$test_history" "git commit -m \"$dbl_escaped_msg\""
fi
}
test_git_commit_prompt_with_append() {
@@ -324,19 +353,19 @@ test_git_commit_prompt_with_append() {
commit_msg="Updating README, no build please"
# Create temporary history file
HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
HISTFILESIZE=1000
HISTSIZE=1000
export HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
export HISTFILESIZE=1000
export HISTSIZE=1000
touch a b c
git add . > /dev/null
git add . >/dev/null
# Zsh 'vared' doesn't handle input via pipe, so replace with function that reads into commit_msg variable.
function vared(){ read commit_msg; }
function vared() { read commit_msg; }
# Test the git commit prompt, by piping a commit message
# instead of user input.
echo "$commit_msg" | GIT_COMMIT_MSG_SUFFIX="[ci skip]" git_commit_prompt > /dev/null
echo "$commit_msg" | GIT_COMMIT_MSG_SUFFIX="[ci skip]" git_commit_prompt >/dev/null
git_show_output=$(git show --oneline --name-only)
assertIncludes "$git_show_output" "$commit_msg \[ci skip\]"
@@ -344,11 +373,14 @@ test_git_commit_prompt_with_append() {
# Test that history was appended correctly.
if [[ $shell == "zsh" ]]; then
test_history="$(history)"
# TODO(ghthor): zsh isn't working here
# assertIncludes "$test_history" "$commit_msg \[ci skip\]"
# assertIncludes "$test_history" "git commit -m \"$commit_msg \[ci skip\]\""
else
test_history="$(cat $HISTFILE)"
fi
assertIncludes "$test_history" "$commit_msg \[ci skip\]"
assertIncludes "$test_history" "git commit -m \"$commit_msg \[ci skip\]\""
fi
}
test_adding_files_with_spaces() {
@@ -358,14 +390,12 @@ test_adding_files_with_spaces() {
touch "$test_file"
e1="$testRepo/$test_file"
git_add_shortcuts 1 > /dev/null
git_add_shortcuts 1 >/dev/null
# Test that file is added by looking at git status
git_status=$(git_status_shortcuts | strip_colors)
assertIncludes "$git_status" "new file: \[1\] \"$test_file"
}
# load and run shUnit2
source "$scmbDir/test/support/shunit2"

View File

@@ -1,32 +0,0 @@
#!/usr/bin/env bash
# Installs dependencies for travis-ci environments.
# Install dependencies, which looks to be just bash & zsh.
#
# Darwin has zsh preinstalled already, so only need to install on Ubuntu.
#
# Note: $TRAVIS_OS_NAME will only be set on text boxes with multi-os enabled,
# so use negation test so it will fail gracefully on normal Travis linux setup.
if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then
# okay, so we know we're probably on a linux box (or at least not an osx box)
# at this point. do we need to install zsh? let's say the default case is no:
needs_zsh=false
# check if zsh is listed in the TEST_SHELLS environment variable, set by
# our travis-ci build matrix.
if [[ $TEST_SHELLS =~ zsh ]]; then needs_zsh=true; fi
# if there is NO $TEST_SHELLS env variable persent (which should never happen,
# but maybe someone has been monkeying with the .travis.yml), run_tests.sh is
# going to fall back onto the default of testing everything, so we need zsh.
if [[ -z "$TEST_SHELLS" ]]; then needs_zsh=true; fi
# finally, we install zsh if needed!
if $needs_zsh; then
sudo apt-get update
sudo apt-get install zsh
else
echo "No deps required."
fi
fi

View File

@@ -2,8 +2,10 @@
# uninstall by (github: bernardofire)
# Remove line from bashrc and zshrc if present.
OS=$(uname -s | awk '{print tolower($0)}')
sed="sed -i"
if [[ $OSTYPE == "Darwin" ]]; then
if [[ "$OS" == "darwin" ]]; then
sed="sed -i ''"
fi