Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The task on Unix #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
## Домашнее задание: [Unix Command Line](https://github.com/yandex-shri/lectures/blob/master/04-unix-cli.md)

Написать сценарий, который находит все файлы не входящие в SVN/Git и перемещает их в ~/.Trash/.

git ls-files . --exclude-standard --others -z | xargs -0 -I {} mv {} ~/.Trash/

присылайте пулл реквесты с решением для SVN или с более элегантным подходом.

См. также: [пост про домашние задания](http://clubs.ya.ru/4611686018427468886/replies.xml?item_no=450).
## Домашнее задание: [Unix Command Line](https://github.com/yandex-shri/lectures/blob/master/04-unix-cli.md)

Написать сценарий, который находит все файлы не входящие в SVN/Git и перемещает их в ~/.Trash/.

git ls-files . --exclude-standard --others -z | xargs -0 -I {} mv {} ~/.Trash/

присылайте пулл реквесты с решением для SVN или с более элегантным подходом.

См. также: [пост про домашние задания](http://clubs.ya.ru/4611686018427468886/replies.xml?item_no=450).

----------------------------------------------------------------------------

Коротко алгоритм работы:

1. Первым параметром передается каталог с требуемым репозиторием для очистки.
2. Проверяется установлен ли git.
3. Проверяется, существует ли каталог ~/.Trash/, если нет, то создается.
4. Далее, если переданный первым параметром каталог действительно является репозиторием git, то все неотслеживаемые файлы из него перемещаются в каталог ~/.Trash/

25 changes: 25 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

MOVE_DIR=~/.Trash/

if [ $# = 0 ]; then
echo "error: repository path required"
exit
fi
REP_DIR=${1/%"/"/""}

git &> /dev/null
if [ $? -ne 127]; then
if ! [ -d "$MOVE_DIR" ]; then
mkdir "$MOVE_DIR"
fi
if [ -d ${REP_DIR}/.git/ ]; then
cd "$REP_DIR"
git ls-files -o -z | xargs -0 -I % mv % "$MOVE_DIR"
echo "git untrack files moving... done"
else
echo "error: git repository is not found"
fi
else
echo "error: git is not found"
fi